Skip to content

Optimize supplement file lookup with direct tree traversal#80

Merged
andrew merged 1 commit intogit-pkgs:mainfrom
miketheman:miketheman/speed-up
Feb 5, 2026
Merged

Optimize supplement file lookup with direct tree traversal#80
andrew merged 1 commit intogit-pkgs:mainfrom
miketheman:miketheman/speed-up

Conversation

@miketheman
Copy link
Contributor

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.

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>
@andrew
Copy link
Contributor

andrew commented Feb 5, 2026

Oh very nice, thanks for providing a second set of eyes on the project ❤️

@andrew andrew merged commit 95f67ad into git-pkgs:main Feb 5, 2026
4 checks passed
@miketheman miketheman deleted the miketheman/speed-up branch February 5, 2026 16:21
@andrew
Copy link
Contributor

andrew commented Feb 5, 2026

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.

2 participants