Skip to content

ignore: skip loading unreachable ignore files - #3496

Merged
BurntSushi merged 1 commit into
BurntSushi:masterfrom
jif-oai:jif/skip-unreachable-ignore-files
Jul 29, 2026
Merged

ignore: skip loading unreachable ignore files#3496
BurntSushi merged 1 commit into
BurntSushi:masterfrom
jif-oai:jif/skip-unreachable-ignore-files

Conversation

@jif-oai

@jif-oai jif-oai commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #2565.

The serial walker currently loads ignore files even when a directory is already skipped or we've reached the max depth. Since we won't visit any children, that work seems unnecessary.

I see that #2566 tried to fix this by adding a new matcher method and threading an is_leaf flag through the ignore internals. This instead reuses the existing add_child_with_entries(path, &[]), so the change stays in walk.rs and the ignore stack still works as before. Let me know if the scoping is not important here

Local benchmarks show:

  • 6–9% faster on a real repo.
  • ~3× faster on nested ignored directories.
  • 22–28× faster on ignore-heavy or sorted searches.
  • No change to parallel traversal.

Also adds a regression test for malformed ignore files at the max depth

@BurntSushi BurntSushi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This makes sense to me! Thank you.

Comment thread crates/ignore/src/walk.rs

assert!(entry.error().is_none());
assert_paths(td.path(), &builder, &["leaf"]);
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nice, clever test.

@BurntSushi

Copy link
Copy Markdown
Owner

On my checkout of the chromium repository (which is loaded with gitignores), I do see a small but measurable improvement here:

$ hyperfine 'rg-master -j1 --max-depth 6 regex-internals' 'rg -j1 --max-depth 6 regex-internals'
Benchmark 1: rg-master -j1 --max-depth 6 regex-internals
  Time (mean ± σ):     867.7 ms ±   6.9 ms    [User: 377.1 ms, System: 488.8 ms]
  Range (min … max):   860.4 ms … 879.6 ms    10 runs

Benchmark 2: rg -j1 --max-depth 6 regex-internals
  Time (mean ± σ):     842.3 ms ±   3.7 ms    [User: 367.7 ms, System: 472.9 ms]
  Range (min … max):   836.4 ms … 846.8 ms    10 runs

Summary
  rg -j1 --max-depth 6 regex-internals ran
    1.03 ± 0.01 times faster than rg-master -j1 --max-depth 6 regex-internals

Nice find!

@BurntSushi
BurntSushi merged commit 435f59f into BurntSushi:master Jul 29, 2026
22 checks passed
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.

perf(ignore): don't search subdirs for git/ignore files if max depth is reached

2 participants