Skip to content

SWF(perf): walk visibility history with one git log pass - #644

Closed
beardthelion wants to merge 1 commit into
mainfrom
devin/1796015632-visibility-log-raw
Closed

beardthelion wants to merge 1 commit into
mainfrom
devin/1796015632-visibility-log-raw

Conversation

@beardthelion

@beardthelion beardthelion commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Clones and fetches on repos with hidden paths start a lot faster. Listing the blobs to withhold on this repo's history went from 7.9 s to 67 ms.

The old walk ran git ls-tree once per commit to collect every (oid, path) pair the node has to hide. That's one process per commit, so cost grew with history length. The new walk gets the same pairs from a single git log --raw -z pass in visibility_pack.rs.

How it works

git log --raw prints each file a commit added or changed against its parent. The walk follows every parent and diffs each merge against its first parent, so a file that only shows up in a merge resolution still gets caught. Subtree and root-tree pairs stay in for the object walk. Output is NUL-delimited, so paths with spaces, newlines, quotes or leading dashes parse as-is.

Behavior change: a cyclic graft or replace history now errors out. The old walk returned a partial list there, which could leak. Non-commit refs and the windowed sweep didn't change.

Correctness

If the walk misses a pair, a hidden file leaks. raw_history_matches_ls_tree_snapshots builds fixture repos and checks that the new set matches the old ls-tree set exactly. Fixtures cover merge-only resolutions, side branches, renames, deletes, gitlinks, nested and empty trees, odd paths, detached HEAD and shallow boundaries.

test git::visibility_pack::tests::raw_history_matches_ls_tree_snapshots ... ok
test git::visibility_pack::tests::blob_paths_times_out_and_reaps_a_hung_walk ... ok
test result: ok. 71 passed; 0 failed; 1 ignored; 0 measured; 2532 filtered out; finished in 3.34s

Benchmark

Rust walk Before (median ms) After (median ms) Speedup
Blob paths 7915.74 67.14 117.9x
Blob and tree paths 9410.12 147.95 63.6x

Method: a Rust test harness timed the old and new code on the Gitlawb/node checkout (1,759 reachable commits, 196 merges). Each variant got one warm-up and five measured runs on an 8-vCPU Xeon (Ubuntu, Git 2.56.0, Rust 1.99.1, unoptimized test profile). This times visibility enumeration only. Pack generation and network transfer aren't included.

Try it

cargo test --locked -p twigpine-node --lib raw_history_matches_ls_tree_snapshots

Not tested

The tests on main don't compile until #643 lands, so CI here will be red until then. There are five unrelated errors, for example cannot find function 'read_caller_key' in this scope and missing field 'trusted_peers' in initializer of 'IpRateLimiter'. The 71 tests above ran with this patch on 91c24ae, the parent of main. Clippy and the full workspace suite haven't run for the same reason.

Summary by CodeRabbit

  • Bug Fixes
    • Improved file and directory visibility results across varied Git history shapes.
    • Malformed history records and cyclic first-parent histories are now rejected, helping prevent incomplete or unreliable results.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

The change adds streamed parsing of raw Git history into path-annotated object sets. Blob, withheld-object, and tree visibility walks use this shared enumeration, with tests comparing its results against ls-tree snapshots across varied history shapes.

Changes: Git history path enumeration

Layer / File(s) Summary
Parse streamed Git history
crates/twigpine-node/src/git/visibility_pack.rs
RawHistory parses and validates raw Git history records. object_paths streams git log --all --raw output into the parser and returns path-annotated object sets.
Use history paths in visibility walks
crates/twigpine-node/src/git/visibility_pack.rs
Blob and withheld-object enumeration now use object_paths. The tree allow-list uses its tree results and retains path-based visibility filtering and structural safety checks.
Validate history enumeration
crates/twigpine-node/src/git/visibility_pack.rs
Tests compare the streamed enumeration with ls-tree snapshots across varied histories. The timeout fixture now stalls git log; test descriptions are updated.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant VisibilityCaller
  participant object_paths
  participant GitLog
  participant RawHistory
  VisibilityCaller->>object_paths: Request object paths
  object_paths->>GitLog: Run git log --all --raw
  GitLog->>RawHistory: Stream raw history records
  RawHistory->>object_paths: Return validated HistoryPaths
  object_paths->>VisibilityCaller: Return blob and tree path pairs
Loading

Suggested reviewers: kevincodex1

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@beardthelion
beardthelion deleted the devin/1796015632-visibility-log-raw branch November 30, 2026 06:02
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