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

Prune paths when using --full-path and a pattern containing the start of string anchor #1279

Open
dustinpho opened this issue Mar 13, 2023 · 0 comments

Comments

@dustinpho
Copy link

dustinpho commented Mar 13, 2023

I recently ran into a scenario where fd could be improved. If the pattern contains the start-of-string (^), fd will continue trying all entries under a subdirectory even if its parent does not 'partially match' the pattern. I ran into a situation where it took several minutes to try to find some files using fd whereas find finished in a few seconds (I assume because it does support pruning with a regex that contains start-of-string -- I did not verify this by looking at the source yet).

The fd command that I had used to compare the performance between the two was:
fdfind <regex> <root-dir> --full-path
and the find command was:
find <root-dir> -regex <regex>
where regex could look like:
^/mnt/foo/bar/([^/]*)/([^/]*)/(baz|qux)/...

Note: This is different than --prune as that option only skips the subdirectory tree if there's a match.

The ideal behavior here is to skip the subdirectory tree if it's impossible to have a match (because there's no partial match) only when matching against full path. If there is not a partial regex match for any of the patterns when we're trying to matching against an full path, then prune (return ignore::WalkState::Skip).

FYI I don't believe the Rust regex library current supports partial matching (rust-lang/regex#678).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant