uutils / uutils/coreutils

du: Use BufWriter<Stdout> and write to stdout when the buffer is near full than directly printing always

Open
#9,146 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - du
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.