Skip to content

tee: improve stdout performance - #12207

Closed
xtqqczze wants to merge 1 commit into
uutils:mainfrom
xtqqczze:tee-throughput3
Closed

tee: improve stdout performance#12207
xtqqczze wants to merge 1 commit into
uutils:mainfrom
xtqqczze:tee-throughput3

Conversation

@xtqqczze

@xtqqczze xtqqczze commented May 9, 2026

Copy link
Copy Markdown
Contributor

Alternative to #12131

@github-actions

github-actions Bot commented May 9, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/retry (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/misc/io-errors is no longer failing!
Note: The gnu test tests/printf/printf-surprise is now being skipped but was previously passing.
Note: The gnu test tests/rm/many-dir-entries-vs-OOM is now being skipped but was previously passing.
Congrats! The gnu test tests/dd/no-allocate is now passing!

@codspeed-hq

codspeed-hq Bot commented May 9, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by ×17

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 316 untouched benchmarks
⏩ 46 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation tee_stdin_file[10000000] 3,970.8 µs 233.4 µs ×17

Comparing xtqqczze:tee-throughput3 (f4d31a6) with main (9bf907d)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@xtqqczze

xtqqczze commented May 9, 2026

Copy link
Copy Markdown
Contributor Author

@oech3 I don't know if this is sound on Windows.

@oech3

oech3 commented May 9, 2026

Copy link
Copy Markdown
Contributor

How about mem::forget to block drop() completely?
I don't like new unsafe on non-Windows and dummy flush anyway.

@xtqqczze

xtqqczze commented May 10, 2026

Copy link
Copy Markdown
Contributor Author

We need to use ManuallyDrop instead of mem::forget to guarantee the file descriptor is never dropped, even in the presence of early returns or panics. This ensures the unsafe code remains sound.

@oech3

oech3 commented May 10, 2026

Copy link
Copy Markdown
Contributor

This is really bad limitation of Rust std...

@oech3

oech3 commented May 10, 2026

Copy link
Copy Markdown
Contributor

Also manual bench on Windows is needed since this removed flush from Win too.

Comment thread src/uu/tee/src/tee.rs Outdated
@xtqqczze

Copy link
Copy Markdown
Contributor Author

This is really bad limitation of Rust std...

@oech3

oech3 commented May 10, 2026

Copy link
Copy Markdown
Contributor

Another possibility is adding URL to nightly std's code to Windows's unsafe code and copy paste it. Then people can use it with minimized concern.

Also I'm considering to add .write() to AsFd instead of .write_all() for cat instead of #12131 (comment) . But it would conflict.

@xtqqczze

Copy link
Copy Markdown
Contributor Author

@oech3 I don't know if this is sound on Windows.

On Windows, it's not valid if we are writing to a console and the code page set to UTF-16. Do we have tests for this?

@oech3

oech3 commented May 11, 2026

Copy link
Copy Markdown
Contributor

If you converted to File, redirecting to file is lossless. No?

@oech3

This comment was marked as outdated.

@xtqqczze xtqqczze closed this May 15, 2026
@oech3

oech3 commented May 15, 2026

Copy link
Copy Markdown
Contributor

We need to have issue about raw reader on Windows.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants