go-git
go-git copied to clipboard
git: worktree, Eliminate duplicate Tree.FindEntry calls in checkout
During checkout operations, Tree.FindEntry was being called twice per file:
- In checkoutChange() to obtain the TreeEntry
- In checkoutChangeRegularFile() via Tree.File(), which internally calls FindEntry again with the same path
This optimization passes the TreeEntry directly from checkoutChange to checkoutChangeRegularFile, eliminating the redundant tree traversal. The blob is now retrieved directly using object.GetBlob() with the hash from the already-found TreeEntry.
Performance impact measured with BenchmarkAlternatesPerformance (40,000 files):
- Tree.FindEntry time reduced from 120.45s to 62.45s (~52% reduction)
- Savings: ~1.55ms per file checkout operation
- Tree.File() usage dropped from 62s+ to negligible (10ms, used elsewhere)
The change maintains identical behavior while significantly improving performance for large checkouts, particularly beneficial for repositories using alternates where object lookups are more expensive.