Skip to content

uucore: share concrete buffered input readers - #15507

Open
limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/io-concrete-buffered-input-11811
Open

limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/io-concrete-buffered-input-11811

Conversation

@limadog9

Copy link
Copy Markdown
Contributor

Use a shared file/stdin enum in expand and uniq so reading needs no boxed trait object. Test mixed buffered/direct reads and both input sources.

Refs #11811.

Comment thread tests/by-util/test_expand.rs Outdated
}

#[test]
fn test_buffered_file_and_stdin_give_same_expansion() {

This comment was marked as resolved.

@limadog9
limadog9 force-pushed the fix/io-concrete-buffered-input-11811 branch from 650efa4 to 4645a59 Compare October 18, 2026 19:57
Comment thread src/uu/uniq/Cargo.toml
clap = { workspace = true }
fluent = { workspace = true }
uucore = { workspace = true, features = ["parser"] }
uucore = { workspace = true, features = ["fs", "parser"] }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is fs needed? uucore::io isn't behind a feature

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error[E0432]: unresolved import `uucore::io`
  --> src/uu/expand/src/expand.rs:18:13
   |
18 | use uucore::io::InputReader;
   |             ^^ could not find `io` in `uucore`
   |
note: found an item that was configured out
  --> src/uucore/src/lib/lib.rs:31:22
   |
30 | #[cfg(all(feature = "fs", any(unix, windows, target_os = "wasi")))]
   |           -------------- the item is gated behind the `fs` feature
31 | pub use crate::mods::io;
   |                      ^^

Comment thread src/uucore/src/lib/mods/io.rs Outdated
///
/// Keep the stdin lock for the lifetime of the reader, preserving any bytes
/// buffered between calls to `Read` and `BufRead`.
pub enum InputReader {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unexpand has almost the same enum, could you please switch it to this one too?

@limadog9
limadog9 force-pushed the fix/io-concrete-buffered-input-11811 branch 3 times, most recently from d5b5489 to e5ecaca Compare October 19, 2026 11:40
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tail/follow-symlink is no longer failing!

@codspeed

codspeed Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Merging this PR will regress 2 benchmarks

⚠️ 121 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

⚠️ 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

⚡ 8 improved benchmarks
❌ 2 regressed benchmarks
✅ 391 untouched benchmarks
⏩ 70 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Memory cp_recursive_deep_tree[(120, 4)] 532.6 KB 699.2 KB -23.82%
❌ Memory du_deep_tree[(100, 3)] 76.5 KB 82.4 KB -7.14%
⚡ Simulation true_consecutive_calls 350.2 ns 294.7 ns +18.85%
⚡ Simulation expand_custom_tabstops[50000] 31.6 ms 29.3 ms +8.05%
⚡ Simulation expand_many_lines[100000] 115.9 ms 107.4 ms +7.92%
⚡ ⚠️ Simulation du_deep_tree[(100, 3)] 1.9 ms 1.9 ms +4.48%
⚡ Simulation uniq_case_insensitive[10000] 2.9 ms 2.8 ms +4.45%
⚡ Simulation uniq_with_count[10000] 3.6 ms 3.5 ms +3.59%
⚡ ⚠️ Simulation uniq_heavy_duplicates[10000] 4.1 ms 4 ms +3.06%
⚡ Simulation uniq_check_chars[(10000, "1")] 4.2 ms 4.1 ms +3.04%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing limadog9:fix/io-concrete-buffered-input-11811 (b801d2b) with main (ae34722)2

Open in CodSpeed

Footnotes

  1. 70 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. ↩

  2. No successful run was found on main (198c615) during the generation of this report, so ae34722 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@limadog9
limadog9 force-pushed the fix/io-concrete-buffered-input-11811 branch from e5ecaca to 60fc39a Compare October 19, 2026 19:52
Comment thread src/uucore/src/lib/mods/io.rs Outdated
#[cfg(not(windows))]
type NativeType = OwnedFd;

/// File or standard input without boxing a trait object.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// File or standard input without boxing a trait object.
/// Represents an input source, either standard input or a file.

try to avoid narrating the diff in comments

Use a shared file/stdin enum in expand, unexpand and uniq so reading
needs no boxed trait object. Generic source types preserve unexpand's
existing outer buffer; other callers keep buffered files and locked
stdin. Declare fs in all three standalone utility dependencies.

Validation: 128 integration tests, Clippy, standalone benchmark checks
and Windows compilation pass. Local release timings on the two unexpand
benchmark inputs remain within 3% of the base; CodSpeed must confirm the
reported simulation regression is resolved.

Refs uutils#11811.
@limadog9
limadog9 force-pushed the fix/io-concrete-buffered-input-11811 branch from 60fc39a to b801d2b Compare October 20, 2026 15:20
@limadog9

Copy link
Copy Markdown
Contributor Author

Updated the doc comment as suggested. Also verified that expand, unexpand, and uniq each enable uucore/fs and pass standalone checks, including their binaries and benchmarks.

This branch has not been deployed

No deployments
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.

4 participants