Skip to content

wc: optimize -c when reading from stdin regular file#11715

Open
venoosoo wants to merge 7 commits intouutils:mainfrom
venoosoo:wc-stdin-metadata-optimization
Open

wc: optimize -c when reading from stdin regular file#11715
venoosoo wants to merge 7 commits intouutils:mainfrom
venoosoo:wc-stdin-metadata-optimization

Conversation

@venoosoo
Copy link
Copy Markdown
Contributor

@venoosoo venoosoo commented Apr 8, 2026

fixes #11610

This PR adds the missing metadata optimization for wc -c (and --bytes) when input comes from stdin redirection (wc -c < file).

GNU coreutils uses fstat() to get the file size directly in this case, avoiding reading the entire file. uutils previously always read the data, making it very slow on large files.

Changes

  • Added try_get_stdin_size() helper using rustix::fs::fstat (Unix)
  • Integrated it into the existing fast path for bytes-only mode
  • Added test for the optimization
  • Falls back safely for pipes, terminals, character devices, etc.

also didnt really know windows so i just added todo to windows implementation

.succeeds()
.stdout_is("50000000\n");
}

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.

This should be part of benchmark

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.

But I don't know how to use stdin at CodSpeed. Maybe, you can just drop the test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

alright

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 8, 2026

GNU testsuite comparison:

GNU test failed: tests/wc/wc-proc. tests/wc/wc-proc is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/printf/printf-surprise is now being skipped but was previously passing.
Congrats! The gnu test tests/cut/cut-huge-range is now passing!

@oech3
Copy link
Copy Markdown
Contributor

oech3 commented Apr 9, 2026

FAIL: tests/wc/wc-proc

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.

wc: wc -c does not optimize stdin as input by metadata

2 participants