Use git_odb_exists instead of git_revparse_single for ObjectExists#2006
Open
tyrielv wants to merge 1 commit into
Open
Use git_odb_exists instead of git_revparse_single for ObjectExists#2006tyrielv wants to merge 1 commit into
tyrielv wants to merge 1 commit into
Conversation
8d6d6dd to
40cce5f
Compare
Replace the heavyweight git_revparse_single call in LibGit2Repo.ObjectExists with git_odb_exists, a purpose-built existence check that skips revparse expression parsing and git_object handle allocation. Benchmarked on an os.2020 enlistment (59.7M objects, 14 packs): - Existing objects: ~800 ns/op (comparable) - Missing objects: 1.3ms vs 2.8ms (2.1x faster) The ODB handle is lazily acquired on first ObjectExists call via git_repository_odb (returns the repo's internal ODB, ref-counted) and freed in Dispose. Falls back to revparse if ODB acquisition fails. Add ObjectCanBeParsed method that retains the old revparse behavior for callers that need corruption detection (LooseObjectsStep), since git_odb_exists only checks index presence, not object integrity. Assisted-by: Claude Opus 4.6 Signed-off-by: Tyrie Vella <tyrielv@gmail.com>
40cce5f to
2f9a2b1
Compare
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.
Summary
Replaces the heavyweight
git_revparse_singlecall inLibGit2Repo.ObjectExistswithgit_odb_exists, a purpose-built existence check that skips revparse expression parsing andgit_objecthandle allocation.Benchmark (os.2020 enlistment, 59.7M objects, 14 packs)
Implementation
git_repository_odb,git_odb_exists,git_odb_free,git_oid_fromstrObjectExistscall, freed inDisposegit_revparse_singleif ODB handle acquisition failsSemantic split: ObjectExists vs ObjectCanBeParsed
git_odb_existsonly checks whether an OID is present in the object store -- it does not decompress or validate the object. This changes behavior forLooseObjectsStep.ClearCorruptLooseObjects, which relied onObjectExistsreturningfalsefor corrupt-but-present loose objects to trigger cleanup.To preserve that behavior, this PR introduces
ObjectCanBeParsed(sha)which retains the oldgit_revparse_singlepath for corruption detection.LooseObjectsStepis updated to callObjectCanBeParsedinstead ofObjectExists.ObjectExistsgit_odb_exists(fast)ObjectCanBeParsedgit_revparse_single(slow but validates)Impact
All
ObjectExistscallers benefit automatically:FindBlobsStage(blob prefetch)EnumerateMissingTreeEntries(diff/tree walk)CommitAndRootTreeExists(commit verification)LooseObjectsSteppreserves existing corruption-detection semantics viaObjectCanBeParsed.Files changed
LibGit2Repo.cs-- new P/Invokes,ObjectExistsusesgit_odb_exists, newObjectCanBeParsedGitRepo.cs-- exposeObjectCanBeParsedthrough the invokerLooseObjectsStep.cs-- callObjectCanBeParsedinstead ofObjectExists