fix: skip ignored directories early during file walk#225
Merged
Conversation
Previously, ignore patterns were only checked against files — the walk still descended into every directory unconditionally. This meant a directory like .venv with thousands of files was fully traversed before each file was individually filtered out, causing significant slowdowns. Now, when a directory itself matches an ignore pattern, filepath.SkipDir is returned immediately, pruning the entire subtree in one step regardless of how many files are inside.
sonamtenzin2
approved these changes
Apr 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, ignore patterns were only checked against files — the walk still descended into every directory unconditionally. This meant a directory like
.venvwith thousands of files was fully traversed before each file was individually filtered out, causing significant slowdowns.Now, when a directory itself matches an ignore pattern,
filepath.SkipDiris returned immediately, pruning the entire subtree in one step regardless of how many files are inside.🛠️ Description
What was broken:
The file walk in both
addlicense/main.goandcmd/headers.goonly applied ignore pattern checks to files. When the walk encountered a directory, it always returnedniland descended into it unconditionally. This meant a directory like.venvwith thousands of Python files was fully traversed — visiting every file, checking each one against the pattern, and then discarding it. The cost scaled linearly with the number of files in the ignored directory.What changed:
Added a directory-level ignore check in both walk functions. When a directory path matches an ignore pattern,
filepath.SkipDiris returned immediately, telling the OS not to read the directory's children at all. Thepath != start/path != "."guard ensures the root directory itself is never accidentally skipped.🔗 External Links
👍 Definition of Done
Test Results
--planmode with missing header--planmode with everything correctignore_year1=true, single-year headers already correct.venvinheader_ignore, 100 files inside.venvnot touchedvendor/**+**/node_modules/**)**/vendor/**inside a subdirectory).venv— verify single skip log entryskipping directory: .venvappears exactly once🤔 Can be merged upon approval?
✅
PCI review checklist
git revert; no schema, data, or config changes involved.