Skip to content

perf(cache,node): batch admit-time outboard capture into one wake (#1790 item 7) - #1879

Merged
alpergundogdu merged 2 commits into
mainfrom
claude/issue-1790-investigation-786f52
Aug 31, 2026
Merged

alpergundogdu merged 2 commits into
mainfrom
claude/issue-1790-investigation-786f52

Conversation

@alpergundogdu

Copy link
Copy Markdown
Contributor

Closes item 7 of #1790 (Group C serve-path hot-path audit). Landed as its own PR, matching the per-item cadence of the #1792 siblings.

Problem

The miss/fill path captures proof nodes one at a time. admit_bao_stream loops over an admitted range's outboard_pairs, calling FillSession::capture per node; each capture fires the per-hash captured notify_waiters(). Every parked serve leg for that hash therefore wakes once per node in the admitted range. The wake count scales with proof-node count, and it is worst exactly where content is popular — many attached readers — so popularity converts directly into wakeup churn (and, until #1790 items 2/8 land, into global-registry-mutex acquisitions).

A second instance of the same loop lives in the node's seed_held_outboard (held-range proof seeding).

Fix

Add HashOutboard::capture_many / FillSession::capture_many: write the whole admit's pairs under one lock acquisition, then notify_waiters once. A shared write_pair helper backs both the single-node capture and the batch form, so capture semantics (idempotent overwrite, leaf ignored, slot bookkeeping) are identical. The notify fires only if at least one internal node was written.

Both admit-time loops switch to the batched form:

  • engine.rs admit_bao_stream post-import capture
  • window.rs seed_held_outboard held-range seed

Wakeups per admit drop from N-readers × N-nodes to N-readers.

Tests

  • capture_many_round_trips_each_internal_node — a batched capture lands every pair a per-node loop would; a serve reader reads back the whole tree.
  • load_awaits_then_resolves_on_capture_many — a parked reader wakes from the batch's single notify.

Full cache suite (399) and node suite green; cargo clippy --workspace, cargo fmt --check, and the anvil-e2e compile gate all clean.

Not in this PR

The other 8 items of #1790 remain open as separate follow-ups. Investigation notes: item 1 is partly already fixed (attach path already skips the allocation); items 2+8 want a per-hash registry lock designed together (item 8's literal fix as written would reopen the #1610 resurrection race); items 4+7 share the admit block, but 7 stands alone cleanly; item 9 is the larger architectural change (overlap discovery with channel funding).

🤖 Generated with Claude Code

 item 7)

The admit path captured proof nodes one at a time, firing the per-hash
`captured` notify per node. Every parked serve leg for that hash then woke
once per node in the admitted range — a wake storm that scaled with proof-node
count and was worst exactly where content is popular (many attached readers).

Add `HashOutboard::capture_many` / `FillSession::capture_many`: write the whole
admit's pairs under one lock acquisition, then `notify_waiters` once. A single
`write_pair` helper backs both the single- and batch-node forms, so capture
semantics stay identical. Switch the two admit-time loops — `admit_bao_stream`'s
post-import capture and `seed_held_outboard`'s held-range seed — to the batched
form. Wakeups per admit drop from N-readers × N-nodes to N-readers.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI lite review requested due to automatic review settings August 31, 2026 13:55

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR reduces serve-path wakeup churn during cache admits by batching outboard proof-node capture into a single lock acquisition and a single Notify wakeup per admit, rather than waking parked readers once per captured node.

Changes:

  • Add batched outboard capture (HashOutboard::capture_many / FillSession::capture_many) to write many proof-node pairs under one lock and notify once.
  • Switch admit-time outboard capture in the cache engine to the batched API.
  • Switch held-range proof seeding in the node serve path to the batched API, and add tests to validate batch capture behavior.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
crates/node/src/handlers/client/window.rs Use batched outboard capture when seeding held-range proof nodes to avoid per-node wakeups.
crates/cache/src/fill_session.rs Introduce shared write_pair helper plus capture_many, and add tests covering batch capture + wake semantics.
crates/cache/src/engine.rs Use capture_many in admit-time proof capture to collapse N proof-node notifies into one per admit.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread crates/cache/src/fill_session.rs Resolved
@github-actions

github-actions Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 82.28% (was 82.27%, ▲ +0.01%) — 69319/84244 lines

File Coverage Lines Δ
crates/cache/src/engine.rs 92.31% 4511/4887 ● 0.00%
crates/cache/src/fill_session.rs 93.77% 843/899 ▲ +0.19%
crates/node/src/handlers/client/window.rs 75.13% 296/394 ● 0.00%
History
Commit Total Δ vs base
6f4f740 82.29% ▲ +0.01%
a796bc6 (HEAD) 82.28% ▲ +0.01%

Copilot review: `write_pair` returned `true` for any interior node even when
the offset→usize conversion saturated or the slot fell outside the buffers,
contradicting its doc and notifying waiters despite storing nothing. Return
`true` only once both the hash bytes and the captured flag — the exact state
`try_load` reads back — are set; bail early on a non-addressable offset.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
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