uutils / uutils/coreutils

`ls`: Investigate printing performance

Open
#7,563 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

U - ls
Dominant language
Rust
Stars
24.1k
Forks
2k
Avg merge
1d 5h
Merged PRs (30d)
365

Description

In seq, we found that directly calling stdout.write_all(str.as_bytes())? is quite a bit faster than using format to do the same operation: write!(stdout, "{str}")?. https://github.com/uutils/coreutils/pull/7562

ls uses a lot of write!(..., "{}", ..)?; patterns. Would be nice to know if switching to write_all would improve performance.

Had a very quick look at samply output, and printing dominate more of the runtime in long format outputs (e.g. ls -l), so maybe it'd be good to start investigating that use case.

For reference, we're doing a bit worse than coreutils:

$ cargo build -r -p uu_ls && taskset -c 0 hyperfine --warmup 3 -L ls target/release/ls,ls "{ls} -lR .git"
    Finished `release` profile [optimized] target(s) in 0.12s
Benchmark 1: target/release/ls -lR .git
  Time (mean ± σ):      32.5 ms ±   0.8 ms    [User: 18.7 ms, System: 13.5 ms]
  Range (min … max):    31.2 ms …  34.4 ms    84 runs
 
Benchmark 2: ls -lR .git
  Time (mean ± σ):      23.7 ms ±   1.5 ms    [User: 11.3 ms, System: 12.0 ms]
  Range (min … max):    23.0 ms …  38.6 ms    114 runs

Summary
  ls -lR .git ran
    1.37 ± 0.10 times faster than target/release/ls -lR .git

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 in the ls implementation by locating its write!(..., "{}", ..)? calls and compare them with seq's direct stdout.write_all pattern. Build the uu_ls release binary and run the provided hyperfine command against ls -lR .git; done means determining whether the output path improves performance and documenting the benchmark result.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.