Skip to content

tail: Performance improvements #7643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 5, 2025

Conversation

karlmcdowall
Copy link
Contributor

Reasonable performance improvements for tail command. Benchmarks...

$ hyperfine -L tail /usr/bin/tail,./target/release/tail.original,./target/release/tail "{tail} -n 100000 ./shakespeare.txt"
Benchmark 1: /usr/bin/tail -n 100000 ./shakespeare.txt
  Time (mean ± σ):       4.8 ms ±   0.4 ms    [User: 2.6 ms, System: 2.3 ms]
  Range (min … max):     4.2 ms …   6.7 ms    539 runs
  
Benchmark 2: ./target/release/tail.original -n 100000 ./shakespeare.txt
  Time (mean ± σ):       4.6 ms ±   0.7 ms    [User: 3.1 ms, System: 1.5 ms]
  Range (min … max):     3.9 ms …  11.7 ms    466 runs
 
Benchmark 3: ./target/release/tail -n 100000 ./shakespeare.txt
  Time (mean ± σ):       3.6 ms ±   0.4 ms    [User: 2.2 ms, System: 1.4 ms]
  Range (min … max):     3.1 ms …   5.9 ms    689 runs
  
Summary
  ./target/release/tail -n 100000 ./shakespeare.txt ran
    1.28 ± 0.24 times faster than ./target/release/tail.original -n 100000 ./shakespeare.txt
    1.35 ± 0.18 times faster than /usr/bin/tail -n 100000 ./shakespeare.txt
$ hyperfine -L tail /usr/bin/tail,./target/release/tail.original,./target/release/tail "{tail} -n +100000 ./shakespeare.txt"
Benchmark 1: /usr/bin/tail -n +100000 ./shakespeare.txt
  Time (mean ± σ):       4.4 ms ±   0.3 ms    [User: 2.3 ms, System: 2.1 ms]
  Range (min … max):     3.9 ms …   5.8 ms    457 runs
  
Benchmark 2: ./target/release/tail.original -n +100000 ./shakespeare.txt
  Time (mean ± σ):       5.3 ms ±   0.4 ms    [User: 3.7 ms, System: 1.6 ms]
  Range (min … max):     4.6 ms …   8.1 ms    450 runs
 
Benchmark 3: ./target/release/tail -n +100000 ./shakespeare.txt
  Time (mean ± σ):       3.3 ms ±   0.6 ms    [User: 1.9 ms, System: 1.4 ms]
  Range (min … max):     2.7 ms …  10.1 ms    645 runs
 
Summary
  ./target/release/tail -n +100000 ./shakespeare.txt ran
    1.34 ± 0.26 times faster than /usr/bin/tail -n +100000 ./shakespeare.txt
    1.64 ± 0.32 times faster than ./target/release/tail.original -n +100000 ./shakespeare.txt

@cakebaker cakebaker changed the title tail: Performace improvements tail: Performance improvements Apr 3, 2025
Copy link

github-actions bot commented Apr 3, 2025

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/stdbuf (passes in this run but fails in the 'main' branch)

@karlmcdowall karlmcdowall force-pushed the tail_forwards_through_file branch from f2a4808 to 47f5ddd Compare April 4, 2025 11:51
Copy link

github-actions bot commented Apr 4, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

Ok(0) => {
return Ok(total);
}
let mut count = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

i know the original code doesn't have any comment but maybe it is the opportunity to explain what it is doing now :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

Copy link
Contributor

Choose a reason for hiding this comment

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

thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updates done. Thanks.

Improve performance of `tail` utility. Tail now uses
performance-optimized memchr APIs when searching through a
file for delimiters.
@karlmcdowall karlmcdowall force-pushed the tail_forwards_through_file branch from 47f5ddd to b264457 Compare April 5, 2025 18:20
@sylvestre sylvestre merged commit 15bb29c into uutils:main Apr 5, 2025
68 checks passed
Copy link

github-actions bot commented Apr 5, 2025

GNU testsuite comparison:

Skip an intermittent issue tests/misc/stdbuf (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/timeout/timeout (fails in this run but passes in the 'main' branch)

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