Skip to content
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

Faster colors #853

Merged
merged 2 commits into from
Nov 14, 2021
Merged

Faster colors #853

merged 2 commits into from
Nov 14, 2021

Conversation

tavianator
Copy link
Collaborator

This can give a significant performance benefit:

$ hyperfine ./fd-{before,after}" --color=always -HI -j1 --search-path=../../linux >/dev/null"
Benchmark #1: ./fd-before --color=always -HI -j1 --search-path=../../linux >/dev/null
  Time (mean ± σ):     802.3 ms ±   4.8 ms    [User: 360.0 ms, System: 531.7 ms]
  Range (min … max):   795.8 ms … 808.9 ms    10 runs

Benchmark #2: ./fd-after --color=always -HI -j1 --search-path=../../linux >/dev/null
  Time (mean ± σ):     263.3 ms ±   3.0 ms    [User: 166.4 ms, System: 190.0 ms]
  Range (min … max):   259.0 ms … 268.0 ms    11 runs

Summary
  './fd-after --color=always -HI -j1 --search-path=../../linux >/dev/null' ran
    3.05 ± 0.04 times faster than './fd-before --color=always -HI -j1 --search-path=../../linux >/dev/null'

Fixes #720. On the other hand, it does lose the distinct colors for
symlinks along the path, as you mentioned in
#720 (comment).

@sharkdp
Copy link
Owner

sharkdp commented Oct 12, 2021

This looks really great - thank you very much. I'd like to do a bit more testing before I approve this, but I'm definitely ok with the "regression" in functionality.

@tavianator
Copy link
Collaborator Author

I even have an idea of how to bring the per-component colors back, but it would need changes to ignore

Comment on lines +63 to +69
for c in path_str[offset..].chars() {
if std::path::is_separator(c) {
offset += c.len_utf8();
} else {
break;
}
}
Copy link
Owner

@sharkdp sharkdp Nov 14, 2021

Choose a reason for hiding this comment

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

I don't understand how this code could be triggered? Wouldn't this imply that the final path component has another path separator inside?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Say the (user supplied) path is a/b///c. parent will be a/b. This loop then advances the length to include a/b///.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah! Thank you.

@sharkdp sharkdp added this to the fd 8.3 milestone Nov 14, 2021
tavianator and others added 2 commits November 14, 2021 17:19
It can be expensive to color each path component separately, requiring a
stat() call on each component.  For deep hierarchies this can result in
quadratic overhead.  Instead, just color the path up to the basename as
a directory.

Fixes sharkdp#720.
@sharkdp sharkdp merged commit fc2a972 into sharkdp:master Nov 14, 2021
@tavianator tavianator deleted the faster-colors branch November 14, 2021 17:20
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.

--color=always ~10x slower
2 participants