Repository navigation
Conversation
A heap sync re-reads each stale slot's record under the slot lock, to leave a slot a title thread rewrote meanwhile to `mirror`. Each re-read was a ReadProcessMemory of its own, about 0.46 us under Wine whatever its size up to a page (12 bytes 462 ns, 4 KiB 538 ns, 64 KiB 1.8 us on an M5 Pro), and a world frame re-reads some 30,000 slots. The stale slots of a page are now read in one call, after the lock is taken and before any slot is made, as each was read before: under the same hold. A run with a page that cannot be read falls back to a call per slot, which gives what it did before (the slot is skipped). VICTORY_SYNC_REREAD=slot keeps a call per slot, for timing. Diagnostics builds log a heap sync line: slots looked at, stale, made again, the time making them and the re-read calls. bench_sync_slots_1_5m_fast_vs_legacy under Wine (release, 5 interleaved runs each, ~39,000 stale slots): fast path 28.7-270 ms (median 81.5) per slot, 10.6-34.7 ms (median 22.3) together. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
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.
What. When a heap sync remakes a page's stale slots (#439's fast path,
HostHeap::mirror_synced_batch), it reads each slot's record again from title memory, under the slot lock, so that it can leave tomirrorany slot a title thread rewrote after the page snapshot. Each slot was read with its ownReadProcessMemorycall. The slots of a page are now read again together (live_records): one call for each run of stale slots within 64 KiB (in practice one per page), made after the slot lock is taken and before any slot is made. That is the same hold of the lock as before, so a slot rewritten meanwhile is still found and deferred tomirror.If a run's read fails (a page of it unmapped meanwhile), its slots are read one at a time, as before, and an unreadable slot is skipped, as before.
VICTORY_SYNC_REREAD=slotbrings back one call per slot, for timing.With
--features diagnosticsthe copy statistics count the re-read calls (SyncRereads).Why. Under Wine a kernel copy costs about 0.46 µs whatever its size up to a page. Measured on an M5 Pro in release: 12 bytes 462 ns, 4 KiB 538 ns, 64 KiB 1.8 µs. In the world the sync remakes some 30,000 slots a frame, mostly per-draw descriptor tables that the title copies into its heaps as bytes. The re-reads therefore cost about 14 ms of every frame's preparing, on the submitting thread.
For reference, in the same probe a buffer view made with
CreateShaderResourceViewcosts 0.8–1.1 µs, aCopyDescriptorsentry 20–22 ns and a null view 5 ns. What remains of the sync is mostly the views it makes; the new diagnostics line says how much of that a cache of made views could save.Tests
descriptor::host::tests::stale_records_are_read_again_together_as_each_alone: stale slots spread over three 64 KiB pages, the middle page reserved but not committed, one slot rewritten after its snapshot. The batched read and the per-slot read give the same result: the live record, the rewritten record where it changed, andNoneon the page with nothing mapped. The run that spans the unmapped page falls back to per-slot reads.fast_heap_sync_handles_placed_null_duplicates_forget_and_concurrent_rewrite, unchanged, still covers a rewrite duringpreparebeing left tomirror.bench_sync_slots_1_5m_fast_vs_legacyunder Wine (release, 5 interleaved runs each way, ~39,000 stale slots in all): fast path 28.7–270 ms (median 81.5) with a call per slot, 10.6–34.7 ms (median 22.3) with the reads together. The machine was loaded and the spread is wide; the minimums differ by ~18 ms, about 39,000 × 0.46 µs.perf/heap-sync-reread-main(fork, d1609d9 + this one commit,d8573e45):tools/macos/test-wine.sh -p victory-gpufordescriptor::,shadow::andmemory::: 132 passed, 0 failed, 5 ignored. Nativecargo test --workspace: all pass exceptpipeline::schedule::tests::compute_waits_stop_after_pipeline_and_frame_caps, which fails the same way on plain origin/main (not this change). gnullvm clippy--all-targets -D warnings, with and without--features diagnostics: clean.cargo xtask policy: ok.In game (M5 Pro, macOS 27, release build, last 120 s of each run). Binary: main 7772921 with this PR and the null-page PR. The off arm sets
VICTORY_SYNC_REREAD=slot VICTORY_NULL_PAGE=0; the on arm leaves both unset.The two changes were measured together. This one's share is expected to be ~13–14 ms of preparing (stale slots × 0.46 µs). A run with only
VICTORY_SYNC_REREAD=slotset, with the new diagnostics line, will give its own number.🤖 Generated with Claude Code