diff --git a/CHANGELOG.md b/CHANGELOG.md index 68762a14..083000de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ TBD === TODO +Performance improvements: + +* [PERF #1381](https://github.com/BurntSushi/ripgrep/pull/1381): + Directory traversal is sped up with speculative ignore-file existence checks. + Bug fixes: * [BUG #1335](https://github.com/BurntSushi/ripgrep/issues/1335): diff --git a/ignore/src/dir.rs b/ignore/src/dir.rs index e4440fc4..54e1f7be 100644 --- a/ignore/src/dir.rs +++ b/ignore/src/dir.rs @@ -689,7 +689,21 @@ pub fn create_gitignore>( builder.case_insensitive(case_insensitive).unwrap(); for name in names { let gipath = dir.join(name.as_ref()); - errs.maybe_push_ignore_io(builder.add(gipath)); + // This check is not necessary, but is added for performance. Namely, + // a simple stat call checking for existence can often be just a bit + // quicker than actually trying to open a file. Since the number of + // directories without ignore files likely greatly exceeds the number + // with ignore files, this check generally makes sense. + // + // However, until demonstrated otherwise, we speculatively do not do + // this on Windows since Windows is notorious for having slow file + // system operations. Namely, it's not clear whether this analysis + // makes sense on Windows. + // + // For more details: https://github.com/BurntSushi/ripgrep/pull/1381 + if cfg!(windows) || gipath.exists() { + errs.maybe_push_ignore_io(builder.add(gipath)); + } } let gi = match builder.build() { Ok(gi) => gi,