Repository navigation
perf(cache): allocate the fill outboard buffer lazily, off the registry lock (#1790 item 1) - #1884
Merged
Merged
Conversation
…ry lock (#1790 item 1) `HashOutboard::new` zeroed the whole `tree.outboard_size()` buffer (~2.7 MB for a 700 MB blob) at construction — and `make_session` builds that outboard under the global `FillRegistry` map lock. So one large-blob miss's claim held the process- wide registry mutex across an MB-scale `vec![0u8; …]`, stalling every other miss's claim, parked-reader wakeup, and teardown for the allocation's duration; concurrent large-blob misses convoyed on the registry, so miss-path concurrency stopped scaling with blob size — backwards. Defer the buffer allocation to the first capture. `HashOutboard::new` is now O(1) (empty vecs); `write_pair` sizes `bytes`/`captured` on the first real interior node it stores, under the per-hash `state` lock — never the global registry lock. A real interior node implies `outboard_size() >= 64`, so an empty buffer is an unambiguous "not yet sized" sentinel. `try_load` already reads an empty buffer as "absent" via `.get()`, so the read side is unchanged. This also drops the wasted allocation a second session for a hash used to make and immediately discard when it adopts the canonical outboard — a lazy buffer never allocates before the adopt. Co-Authored-By: Claude Opus 4.8 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR addresses a miss/fill hot-path contention issue in the cache by making HashOutboard construction O(1) and deferring the large outboard buffer allocation/zeroing until the first actual capture, so the global FillRegistry lock is no longer held across MB-scale allocations.
Changes:
- Make
HashOutboard::newallocate empty vectors instead of zeroing the full outboard buffer immediately. - Lazily allocate and size the outboard
bytes/capturedbuffers on the first interior-node capture insideHashOutboard::write_pairunder the per-hash lock. - Add a regression test asserting that outboard buffers start empty and are allocated on first capture.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…esentable Copilot review: the lazy `write_pair` sizing fell back to `usize::MAX` when `tree.outboard_size()` did not fit `usize`, which would attempt `vec![0u8; usize::MAX]` and abort the process. Degrade the same way the adjacent `idx` guard does — return `false` (not capturable) — rather than allocate the maximum. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Coverage reportTotal: 82.32% (was 82.31%, ● 0.00%) — 69502/84431 lines
History
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item 1 of #1790 (Group C serve-path hot-path audit), landed as its own PR — same per-item cadence as the merged item 7 (#1879), item 5 (#1882), and open item 3 (#1883).
Problem
HashOutboard::newzeroed the wholetree.outboard_size()buffer (~2.7 MB for a 700 MB blob) at construction, andmake_sessionbuilds that outboard under the globalFillRegistrymap lock. So a single large-blob miss'sclaimheld the process-wide registry mutex across an MB-scalevec![0u8; …], stalling every other miss's claim, parked-reader wakeup, and teardown for the allocation's duration. Concurrent large-blob misses convoyed on the registry — miss-path concurrency stopped scaling with blob size, which is backwards.Fix
Defer the buffer allocation to the first capture:
HashOutboard::newis now O(1) — empty vecs, no zeroing.write_pairsizesbytes/capturedon the first real interior node it stores, under the per-hashstatelock — never the global registry lock. A real interior node impliesoutboard_size() >= 64, so an empty buffer is an unambiguous "not yet sized" sentinel.try_loadalready reads an empty buffer as "absent" via.get(), so the read side is unchanged.The MB-scale zeroing now lands at first-capture time under a per-hash lock (where an admit already does far heavier store I/O), off the global mutex that every other hash's claim contends. This also drops the wasted allocation a second session for a hash used to make and immediately discard when it adopts the canonical outboard — a lazy buffer never allocates before the adopt.
Why not the issue's literal "allocate before locking"
claimcan't know Own/Mix/Attach until it holds the lock (the single-lock decision closes a coalescing TOCTOU), so eager pre-lock allocation would waste a 2.7 MB buffer on the common attach case. Lazy allocation reaches the same goal — "registry critical section becomes O(1); no MB-scale zeroing under the global mutex; no wasted allocations on attach" — without that tension, and in one self-contained file.Tests
outboard_buffer_is_allocated_lazily_on_first_capture(new) — a freshly built session allocates no buffer; the first capture sizes it to the full outboard.siblings_share_one_per_hash_outboard, and the park-then-resume families all stay green.Remaining #1790 items
Items 2, 4, 8, 9 remain (7 merged; 5 in #1882 merged; 3 in #1883; 6 closed as already-considered — collides with a documented deliberate decision in
retry.rs, see the issue comment).🤖 Generated with Claude Code