Skip to content

cat: avoid unnecessary alloc on Linux#11906

Open
oech3 wants to merge 1 commit intouutils:mainfrom
oech3:cat-st
Open

cat: avoid unnecessary alloc on Linux#11906
oech3 wants to merge 1 commit intouutils:mainfrom
oech3:cat-st

Conversation

@oech3
Copy link
Copy Markdown
Contributor

@oech3 oech3 commented Apr 19, 2026

Split a code path which is rarely called to a different function instead of using vec! like #11675 .

Comment thread src/uu/cat/src/cat.rs Outdated
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 19, 2026

GNU testsuite comparison:

GNU test failed: tests/tail/retry. tests/tail/retry is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/tail/tail-n0f (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)

@xtqqczze
Copy link
Copy Markdown
Contributor

We should probably double check CodSpeed benchmarks with hyperfine for anything allocation related.

@oech3
Copy link
Copy Markdown
Contributor Author

oech3 commented Apr 19, 2026

cat_default[10000000]
src/uu/cat/benches/cat_bench.rs
0%
89.4 µs
89.3 µs
cat_default[10000]
src/uu/cat/benches/cat_bench.rs
0%
197.3 µs
197.1 µs

@oech3
Copy link
Copy Markdown
Contributor Author

oech3 commented Apr 19, 2026

Check unnecessary alloc bypass:

$ target/release/cat8192 /etc/hostname
m
$ strace -o /dev/null -e inject=splice:error=ENOSYS target/release/cat8192 /etc/hostname
fish: Job 1, 'strace -o /dev/null -e inject=s…' terminated by signal SIGSEGV (Address boundary error)

@oech3 oech3 marked this pull request as ready for review April 19, 2026 20:26
@oech3
Copy link
Copy Markdown
Contributor Author

oech3 commented Apr 19, 2026

> truncate -s 0 /tmp/huge
> taskset -c 1 hyperfine -N "target/release/cat-main /tmp/huge" 'target/release/cat64 /tmp/huge'
Benchmark 1: target/release/cat-main /tmp/huge
  Time (mean ± σ):       1.0 ms ±   0.2 ms    [User: 0.4 ms, System: 0.5 ms]
  Range (min … max):     0.8 ms …   3.6 ms    2736 runs
 
Benchmark 2: target/release/cat64 /tmp/huge
  Time (mean ± σ):     999.4 µs ± 207.1 µs    [User: 382.1 µs, System: 494.9 µs]
  Range (min … max):   819.8 µs … 3966.6 µs    1844 runs
 
Summary
  target/release/cat64 /tmp/huge ran
    1.01 ± 0.30 times faster than target/release/cat-main /tmp/huge

Comment thread src/uu/cat/src/cat.rs
Comment thread src/uu/cat/src/cat.rs
Comment thread src/uu/cat/src/cat.rs
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.

2 participants