Skip to content

Stop merge-base walks when one paint side is exhausted - #3003

Draft
Sebastian Thiel (Byron) wants to merge 1 commit into
mainfrom
merge-base-perf
Draft

Sebastian Thiel (Byron) wants to merge 1 commit into
mainfrom
merge-base-perf

Conversation

@Byron

Copy link
Copy Markdown
Member

Tasks

  • refackiew

Created by Codex on behalf of Byron. Byron will review before this is ready to merge.

Summary

Stop the merge-base walk once either non-stale paint frontier is exhausted and no pending merge-base candidates remain. This avoids following unrelated ancestry after it can no longer contribute a result. Per-color counters also replace the queue scan used to check whether all entries are stale.

Context

This ports the side-exhaustion optimization from Git's commit 02d7ba092d, identified while comparing Git's current merge-base computation with gix.

The early exit requires positive, unsaturated generation numbers. Missing, zero, and saturated generations retain the existing stale-or-empty termination because commit-date ordering can revive an apparently exhausted color. Pending candidates count toward both colors, and queue membership tracking keeps counts correct when commits gain flags or inputs are duplicated. The API still returns all merge bases and removes redundant candidates afterward.

Regression tests reuse existing fixtures to verify skipped ancestry, pending candidates, both input orders, duplicate inputs, graph reuse, and clock skew with unreliable generations.

Validation

  • The skipped-ancestry regression failed before the implementation and passes afterward.
  • GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix-revision --all-features — 114 tests passed.
  • GIX_TEST_IGNORE_ARCHIVES=1 GIX_TEST_FIXTURE_HASH=sha256 cargo test -p gix-revision --all-features -- --quiet — 114 tests passed.
  • cargo fmt --all -- --check — passed.
  • cargo clippy -p gix-revision --all-features --all-targets -- -D warnings -A unknown-lints --no-deps — passed.

Clippy without --no-deps encounters a pre-existing collapsible_if warning in gix-tempfile/src/registry.rs. The configured removed Clippy lint also emits a warning. No timing benchmark was run; the regression checks that unnecessary ancestry is not loaded.

User Prompts

did it learn new tricks to abort the search earlier, i.e. when no color is left instead of waiting for everythign to be stale, preventing long unnecessary walks?

Implement this in Gix as well.

…sted

The merge-base walk kept following unrelated ancestry while any queued
commit remained non-stale, even after one paint color could no longer
contribute a merge base. Its termination check also scanned the queue
on every iteration.

Adapt Git's side-exhaustion optimization from `02d7ba092d`: count
non-stale queued commits carrying each color and stop when either count
reaches zero in the topologically ordered region. Candidates contribute
to both counts so they are processed before termination. Track queue
membership to handle flag changes and duplicate inputs without counting
a commit twice.

Keep the existing stale-only termination for missing, zero, or saturated
generations, where date ordering can revive an apparently exhausted
color. Continue removing redundant candidates after the paint walk.

Use existing fixtures to prove that unrelated ancestry is skipped and
cover pending candidates, duplicate inputs, graph reuse, and clock skew.
The skipped-ancestry regression fails before this change.

Validation:
- `GIX_TEST_IGNORE_ARCHIVES=1 cargo test -p gix-revision --all-features`
- The same 114 tests with `GIX_TEST_FIXTURE_HASH=sha256`
- `cargo fmt --all -- --check`
- `cargo clippy -p gix-revision --all-features --all-targets -- -D warnings -A unknown-lints --no-deps`

Clippy without `--no-deps` encounters a pre-existing `collapsible_if`
warning in `gix-tempfile/src/registry.rs`.
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