go-git icon indicating copy to clipboard operation
go-git copied to clipboard

git: worktree, Eliminate duplicate Tree.FindEntry calls in checkout

Open cedric-appdirect opened this issue 2 months ago • 0 comments

During checkout operations, Tree.FindEntry was being called twice per file:

  1. In checkoutChange() to obtain the TreeEntry
  2. 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.

cedric-appdirect avatar Nov 24 '25 19:11 cedric-appdirect