Skip to content

perf(repo): walk only the --all delta after the HEAD pass - #75

Merged
Ian-stetsenko merged 1 commit into
mainfrom
perf/lore-index-delta-pass
Nov 3, 2026
Merged

Ian-stetsenko merged 1 commit into
mainfrom
perf/lore-index-delta-pass

Conversation

@TommyC81

@TommyC81 TommyC81 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to the review note on #74: getLoreIdIndex walked HEAD history twice. The HEAD pass seeds every reachable id, then the --all pass re-walked and re-parsed those same commits before first-wins deduplication discarded the duplicate work. Unmeasurable on small repos; on the 1.4M-commit corpus from #55 every index build pays the double walk.

Design: resolve first, walk the pin. getLoreIdIndex now resolves HEAD once, walks exactly that pinned commit, then runs git log --all --not <pin> for the delta. Resolving before walking is what makes the pin sound under concurrency: the first pass always walks exactly the commit the second pass excludes, so a landing commit or a concurrent branch switch can neither exclude walked history from the delta pass nor hide new history from it. Plain --all remains the fallback whenever HEAD cannot be resolved (unborn HEAD: a single --all walk) or the pinned walk fails (the exclusion is given up so --all covers HEAD) - the union of the passes never shrinks below git log --all.

Semantics unchanged: pinned-pass atoms insert first, the delta pass fills only missing ids (a side branch can never shadow the current branch, #57), newest-first first-wins within each pass matches grep-based findByLoreId.

Tests: unit tests pin the exact args of both passes in all three paths (pinned walk then delta; unresolved HEAD, single --all; failed walk, plain --all); a real-git integration test asserts the index holds the side-branch-only id and the HEAD-reachable atom wins the shared id. Typecheck clean, full suite 508/508 on Windows.

Happy to benchmark against a large corpus (e.g. the blobless kernel clone from #55) if useful.

Follow-up on PR #74 (d181468e), from the maintainer's review note: getLoreIdIndex walked HEAD history twice. The HEAD pass seeds every reachable id, then the --all pass re-walked and re-parsed those same commits before first-wins deduplication discarded the duplicate work. On small repositories the cost is unmeasurable; on a 1.4M-commit corpus (issue #55) every index build pays the double walk. The index now resolves HEAD once, walks exactly that pinned commit, then runs git log --all --not <pin> for the delta. Resolving before walking is what makes the pin sound under concurrency: the first pass always walks exactly the commit the second pass excludes, so the exclusion boundary stays self-consistent under concurrent branch movement or landing commits - walked history is never dropped from the delta pass and new history is never hidden from it (which duplicate of a mid-build-landing shared Lore-id wins first-wins remains timing-dependent, as it was before). Plain --all remains the fallback whenever HEAD cannot be resolved (unborn HEAD on a fresh repository, a single --all walk) or the pinned walk fails (the exclusion is given up so --all covers HEAD). Semantics are unchanged: pinned-pass atoms are inserted first and the delta pass only fills missing ids, so a side branch can never shadow the current branch (issue #57), and newest-first first-wins within each pass keeps the same atom a grep-based findByLoreId returns. Coverage: unit tests pin the exact args of both passes in all three paths (pinned walk then delta; unresolved HEAD, single --all; walk failure then plain --all), and a real-git integration test asserts the index itself holds the side-branch-only id and lets the HEAD-reachable atom win the shared id, alongside the existing shadowing and unborn-HEAD integration tests.

Lore-id: de1d01a2
Constraint: Resolve HEAD before walking and walk the pinned commit: the pin must always equal what the first pass walked, or the delta exclusion can misclassify history under concurrent branch movement.
Constraint: Unresolved HEAD and failed pinned walk both keep the plain --all fallback, so the union of the passes never shrinks below git log --all.
Constraint: Index semantics stay identical to PR #74: HEAD-reachable atoms win, delta pass fills only missing ids, first-wins within each pass.
Tested: npm run typecheck: clean
Tested: Full suite on Windows: 508 tests in 34 files, all passing
Tested: Unit: pass-1 args are [pin], pass-2 args ['--all', '--not', pin] after a successful walk; unresolved HEAD runs a single ['--all'] walk; a failed pinned walk falls back to ['--all'] with head atoms retained
Tested: Real-git integration: the index holds the side-branch-only id (cafe1234) and the HEAD-reachable atom wins the shared id (deadbeef); existing unborn-HEAD and shadowing integration tests pass
Related: d181468e
Confidence: high
Scope-risk: narrow
Reversibility: clean
@TommyC81

TommyC81 commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator Author

Cross-linking the open PRs: #75, #76, and #77 were merged together locally and verified as a set (clean auto-merges, typecheck clean, combined suite 512/512 on Windows). #77 touches the same function as this PR; both merge orders were verified. Merging in any order is safe.

@Ian-stetsenko
Ian-stetsenko merged commit 3c6db99 into main Nov 3, 2026
3 checks passed
@TommyC81
TommyC81 deleted the perf/lore-index-delta-pass branch November 3, 2026 14:28
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