Skip to content

fix: stop find_nearest_bookmarked_ancestors re-walking merge ancestors combinatorially (RIG-3585) - #5

Draft
rigel-mintaka wants to merge 1 commit into
mainfrom
upstream-vcs/rig-3585-rewalk-dedup
Draft

rigel-mintaka wants to merge 1 commit into
mainfrom
upstream-vcs/rig-3585-rewalk-dedup

Conversation

@rigel-mintaka

Copy link
Copy Markdown
Contributor

find_nearest_bookmarked_ancestors recursed with no visited set, re-expanding a shared ancestor once per path that reaches it — one jj log subprocess per visit. On a history with merge commits outside trunk() this is exponential in the number of merges: a 12-rung merge ladder spawns 8194 jj invocations and a real 136-commit / 26-merge repo did not terminate in 200s.

Thread a visited set (keyed on commit id) through the recursion so each commit is expanded at most once. The set of boundary ancestors is unchanged — a boundary found on the first visit already bubbles to the root and the caller deduplicates via BTreeSet — so the walk becomes linear with identical output. A test-only jj subprocess counter on Jujutsu backs a regression test asserting the invocation count stays linear over a 12-rung merge ladder (8194 without the fix, well under 200 with it).

Spec-impact: none. Refs RIG-3585

Co-authored-by: Matt Wilkinson matt@rigel.build

@linear-code

linear-code Bot commented Sep 11, 2026

Copy link
Copy Markdown

RIG-3585

…s combinatorially (RIG-3585)

`find_nearest_bookmarked_ancestors` recursed with no visited set, re-expanding a shared ancestor once per path that reaches it — one `jj log` subprocess per visit. On a history with merge commits outside `trunk()` this is exponential in the number of merges: a 12-rung merge ladder spawns 8194 `jj` invocations and a real 136-commit / 26-merge repo did not terminate in 200s.

Thread a `visited` set (keyed on commit id) through the recursion so each commit is expanded at most once. The set of boundary ancestors is unchanged — a boundary found on the first visit already bubbles to the root and the caller deduplicates via `BTreeSet` — so the walk becomes linear with identical output. A test-only `jj` subprocess counter on `Jujutsu` backs a regression test asserting the invocation count stays linear over a 12-rung merge ladder (8194 without the fix, well under 200 with it).

Spec-impact: none. Refs RIG-3585

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@rigel-mintaka
rigel-mintaka force-pushed the upstream-vcs/rig-3585-rewalk-dedup branch from c9286a7 to 090ae9f Compare September 11, 2026 23:24
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.

1 participant