- Notifications
You must be signed in to change notification settings - Fork868
Alternate push bug fix#1762
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Open
cedric-appdirect wants to merge3 commits intogo-git:mainChoose a base branch fromcedric-appdirect:alternate-push-bug
base:main
Could not load branches
Branch not found:{{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline, and old review comments may become outdated.
Open
+248 −17
Conversation
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
Problem:When looking up objects via alternates, the current implementation createsa new ObjectStorage instance for every lookup. This causes severe performancedegradation because each NewObjectStorage() call re-reads the alternates file,re-initializes packfile index structures, and re-loads packfile indexes.For operations that enumerate many objects (push, log, diff), this causes formy test repository with 35K files:- 500+ GB memory allocation (repeatedly loading indexes)- 195+ seconds CPU time for object enumeration- Massive disk I/O (re-reading same packfiles)Benchmarks show git push with alternates is 173x slower than git CLIon a repository with 35K files.Solution:Cache ObjectStorage instances for alternate repositories using sync.Oncefor thread-safe lazy initialization. The cached instances share the sameobjectCache to maximize cache hits across all storages.This fix also extends alternates support to HasEncodedObject andEncodedObjectSize methods which previously did not check alternates.Performance impact:- Object lookups via alternates: ~100x faster- Memory usage: ~500x reduction per lookup- Push operation on 35k file repo: 287s to ~20sSigned-off-by: Cedric BAIL <cedric.bail@appdirect.com>
Add comprehensive tests for the alternates caching functionality:- TestObjectStorageMultipleAlternates: verify multiple alternates work- TestObjectStorageAlternatesHasEncodedObject: verify HasEncodedObject- TestObjectStorageAlternatesEncodedObjectSize: verify EncodedObjectSizeSigned-off-by: Cedric BAIL <cedric.bail@appdirect.com>
Add benchmarks to measure and prevent regression in alternatesperformance using b.Run sub-benchmarks and modern b.Loop():- BenchmarkAlternatesObjectLookup/EncodedObject- BenchmarkAlternatesObjectLookup/HasEncodedObject- BenchmarkAlternatesObjectLookup/EncodedObjectSizeThese benchmarks document the expected performance characteristicsand help catch regressions in future changes.Note: PlainClone with Shared:true cannot be used here due to importcycle (repository.go imports storage/filesystem), so alternatesare set up manually following the same pattern.Signed-off-by: Cedric BAIL <cedric.bail@appdirect.com>
Sign up for freeto 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.
This started with a massive memory spike when pushing a single change on a repository using alternate. Issue was due to continuous creation of NewObjectStorage. Additionally I realized that when doing a Clone it was doing a very large amount of data transfer as it wasn't able to find the hash from the alternate as it wasn't doing the lookup at all.
I think the code could be better if I was to use range-over-func, but I am not sure that is ok pattern for this repository. Let me know if that would be preferred or if you have any better idea on how to implement this.