Optimize supplement file lookup with direct tree traversal#80
Merged
andrew merged 1 commit intogit-pkgs:mainfrom Feb 5, 2026
Merged
Optimize supplement file lookup with direct tree traversal#80andrew merged 1 commit intogit-pkgs:mainfrom
andrew merged 1 commit intogit-pkgs:mainfrom
Conversation
Replace O(n) whole-tree iteration with O(1) subtree lookup when finding supplement files (lockfiles) in the same directory as a manifest. Before: tree.Files().ForEach() iterated every file in the repository, then filtered by directory path - O(total files in repo) per manifest. After: tree.Tree(dir) navigates directly to the target directory, then iterates only its direct entries - O(files in directory) per manifest. Performance improvement on a repository with 8619 commits: - Before: 5:20 (320 seconds) - After: 12 seconds - Speedup: ~26x Also fixes a subtle bug where filepath.Dir() was used (platform-dependent path separators) instead of explicit "/" (git's path convention), and removes mutation of the captured `dir` variable inside the ForEach closure. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
|
Oh very nice, thanks for providing a second set of eyes on the project ❤️ |
Contributor
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.
Replace O(n) whole-tree iteration with O(1) subtree lookup when finding supplement files (lockfiles) in the same directory as a manifest.
Before: tree.Files().ForEach() iterated every file in the repository, then filtered by directory path - O(total files in repo) per manifest.
After: tree.Tree(dir) navigates directly to the target directory, then iterates only its direct entries - O(files in directory) per manifest.
Performance improvement on a repository with 8619 commits:
Also fixes a subtle bug where filepath.Dir() was used (platform-dependent path separators) instead of explicit "/" (git's path convention), and removes mutation of the captured
dirvariable inside the ForEach closure.