Skip to content

tee: improve stdout performance#12207

Draft
xtqqczze wants to merge 1 commit intouutils:mainfrom
xtqqczze:tee-throughput3
Draft

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

Conversation

@xtqqczze
Copy link
Copy Markdown
Contributor

@xtqqczze xtqqczze commented May 9, 2026

Alternative to #12131

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 9, 2026

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
Copy link
Copy Markdown

codspeed-hq Bot commented May 9, 2026

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
Copy link
Copy Markdown
Contributor Author

xtqqczze commented May 9, 2026

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

@oech3
Copy link
Copy Markdown
Contributor

oech3 commented May 9, 2026

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

@xtqqczze
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
Copy link
Copy Markdown
Contributor

oech3 commented May 10, 2026

This is really bad limitation of Rust std...

@oech3
Copy link
Copy Markdown
Contributor

oech3 commented May 10, 2026

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
Copy link
Copy Markdown
Contributor

oech3 commented May 10, 2026

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.

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