Skip to content

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

Merged
beardthelion merged 5 commits into
mainfrom
perf/visibility-log-raw
Dec 1, 2026
Merged

beardthelion merged 5 commits into
mainfrom
perf/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 repository visibility results across commit histories, including merges, root-level trees, and changes to files and directories.
    • Visibility checks continue to account for objects referenced directly by non-commit refs.
    • Incomplete or malformed history data now results in an error rather than potentially producing partial visibility results.

@coderabbitai

coderabbitai Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change replaces per-commit tree enumeration with a streaming git log --raw history walk. Blob and tree visibility checks use paths from that walk. Tests compare results with the previous enumeration across varied history shapes.

Changes: Git history visibility enumeration

Layer / File(s) Summary
Parse and validate streaming history
crates/twigpine-node/src/git/visibility_pack.rs
object_paths parses raw Git history records and tracks paths and first-parent links. Tests compare its output with the previous ls-tree walk and cover malformed data, timeouts, and varied repository states.
Use history paths in visibility checks
crates/twigpine-node/src/git/visibility_pack.rs, crates/twigpine-node/src/api/ipfs.rs, crates/twigpine-node/src/api/repos.rs
blob_paths, withheld_object_oids_bounded, and the tree allow-list use object_paths. API test fixtures and assertions now recognize or simulate the log walk. The separate tree and root-tree passes are removed.

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

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant VisibilityWalk
  participant Git
  participant RawHistory
  participant VisibilityCheck
  VisibilityCheck->>VisibilityWalk: Request blob or tree paths
  VisibilityWalk->>Git: Run git log --raw
  Git->>RawHistory: Stream raw history records
  RawHistory->>VisibilityWalk: Return parsed object paths
  VisibilityWalk->>VisibilityCheck: Provide paths for visibility checks
Loading

Possibly related PRs

  • Twigpine/node#84: Changes the ref scope and classification that feed blob_paths, which this change rewrites using git log --raw.

Suggested reviewers: kevincodex1, jatmn

Merge Risk: Minimal · up to 46cae

The change speeds up how visibility checks enumerate repository history and keeps the results equivalent to the old walk. No concrete merge-blocking defect was found. The full test suite and Clippy still need to run once the unrelated build fix lands.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "SWF(perf): walk visibility history with one git log pass" matches the main change. The PR replaces the per-commit git ls-tree walk in visibility_pack.rs with a single git log --raw pass, an…
Description check Passed The description covers the summary, motivation, how the new walk works, correctness testing, benchmarks, and how to verify. It explains the behavior change for cyclic graft or replace histories and th…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "SWF(perf): walk visibility history with one git log pass" matches the main change. The PR replaces the per-commit git ls-tree walk in visibility_pack.rs with a single git log --raw pass, and the raw summary confirms object_paths and allowed_tree_set_for_caller_bounded now use the shared history walk. The title is specific and follows a conventional prefix style.

Full details: Description check

Explanation

The description covers the summary, motivation, how the new walk works, correctness testing, benchmarks, and how to verify. It explains the behavior change for cyclic graft or replace histories and the CI status. Several template sections are missing or unfilled: the 'Closes #' issue link is blank, the 'Kind of change' checkboxes are not ticked, the 'What changed' section does not list crates touched (twigpine-node is implied), and the 'Before you request review' checklist is absent. The 'Protocol & signing impact' section is also absent. The author did not mention whether docs or .env.example were updated.

Resolution

Optionally: tick the 'Kind of change' box (Performance is not listed; Refactor or Feature may apply), fill in or remove the 'Closes #' line, name the crate in 'What changed', and add the 'Before you request review' and 'Protocol & signing impact' checklists or state they are N/A.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Usage-based review receipt

Note

This review was completed with usage-based billing: files reviewed beyond your plan's included limits are billed at $0.25/file. View usage-based billing.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6304bf80-e46b-467d-a8c8-71d30dbbb666
Commits

Reviewing files that changed from the base of the PR and between b3d03d1 and 46cae5d.

Files selected for processing: 3

  • crates/twigpine-node/src/api/ipfs.rs
  • crates/twigpine-node/src/api/repos.rs
  • crates/twigpine-node/src/git/visibility_pack.rs
Files skipped from review as they are similar to previous changes: 1

  • crates/twigpine-node/src/git/visibility_pack.rs

Limit details: You’ve used the included review currently available.

@beardthelion
beardthelion requested a review from jatmn November 30, 2026 06:14

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the change for merge readiness. The performance refactor looks sound on inspection; workspace CI is still blocked until unrelated compile fixes land.

Merge readiness

Required CI before merge. fmt + clippy, test (stable|beta), build --release, and MSRV are failing because twigpine-node does not compile on current main (e.g. missing trusted_peers on IpRateLimiter in server.rs, read_caller_key in api/repos.rs). The author notes dependency on PR #643. After that lands, re-run the full PR check suite on this branch and confirm the visibility tests pass, especially:

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

Update the blob-walk module comment (~visibility_pack.rs lines 626–667). It still documents phase-1 git rev-list --all + per-commit ls-tree for blob_paths, but production now uses object_paths (git log --raw) plus unchanged phase-2 non_commit_ref_sets. Align that comment with the new walk so security review does not rely on the old algorithm description.

Branch is current with main. Merge-base matches live origin/main (6168c559); no rebase drift observed.

Intentional behavior change (acceptable). Cyclic graft/replace histories now error in object_paths instead of returning a partial withhold set — fail-closed per PR description.

Findings

No findings.

@beardthelion

Copy link
Copy Markdown
Collaborator Author

Merged main for the compile fix from #643 and updated the blob_paths doc comment to describe the git log --raw walk.

The rerun also exposed 22 lib tests failing on this branch (7 in api::ipfs::tests, 15 in api::repos::tests). Their git shims and walk counters were keyed on rev-list and ls-tree, and the walk now runs one git log --all --raw, so the fakes never fired. I converted the shims and counters to the new command and kept the rev-list arms that the delta scan and reachability code still reach. No production code changed.

Checked at this head: the 22 tests pass alone, the ipfs and repos test modules pass (80 and 249 tests), the full workspace test run is 3833 passed and 0 failed, and fmt and clippy are clean. With the new shim arms disabled, the 22 tests fail on their own assertions again, so they do bind to the walk. Four converted repos tests assert that no walk or scan ran; they stay green with the arms disabled, so they only show the counter still matches the new command.

@beardthelion
beardthelion added this pull request to the merge queue Dec 1, 2026
Merged via the queue into main with commit cb4f277 Dec 1, 2026
22 checks passed
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