du: Use BufWriter<Stdout> and write to stdout when the buffer is near full than directly printing always
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 24.1k
- Forks
- 2k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 365
Description
From https://github.com/uutils/coreutils/issues/6845, I believe a contributor to why the du implementation here is slower is because it directly prints small content to stdout() repeatedly and at first go within print_stat() function.
For a command like du, which does heavy printing to stdout(), we should use a BufWriter instead and print from this buffer every time the buffer needs to be flushed (when the buffer is full or can't hold the next string to store inside). This way we can reduce the number of write syscalls and locks we perform to stdout().
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the du implementation's print_stat() function, where the issue says small output is written directly to stdout(). Trace how stdout() is used there, then verify that output is unchanged while writes are buffered with BufWriter and flushed when needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- cli, performance
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100