Repository navigation
Conversation
…t lock Before every submission the heap sync makes again the slots whose records the title copied into its shader-visible heaps as bytes: some 40,000 a frame in the prologue's world (about 22,000 left null, the rest views of only ~1,700 distinct records). Each went through HostHeap::mirror, which takes the heap's slot lock (`made`) once a slot, while the title's threads recording draws make their table slots under the same lock. On an M5 Pro that cost 217 ms of a 557 ms frame in a release build, about half of it waiting for the lock. HostHeap::mirror_synced does for each slot exactly what mirror does on the heap-sync path, but with the lock taken once for a page's slots: what each view needs is prepared first without the lock, as mirror does; a slot the title wrote again meanwhile is left to mirror; whether a view is still current is asked under the lock, as mirror asks; views are unpinned after the lock. mirror's null path and its making of a slot move into unmake_locked and make_locked, which both use. Measured in the game (M5 Pro, D3DMetal 4.0 beta 3, same save and key script), interleaved runs of one diagnostics binary with the batching on and off: heap sync 297/231 -> 92/145 ms a frame, preparing 428/368 -> 212/335 ms, frame 750/668 -> 462/639 ms. Test: a_slot_rewritten_while_a_heap_sync_prepares_is_left_as_written_last. Diagnostics builds now also log where a heap sync's time goes, per frame: the pages a heap sync read and of their slots those passed by as made from their record, those holding no view, those checked under the locks (and of them those in blocks not verified since views were last forgotten) and those made again, with the time spent checking, making, reading pages and waiting for the heaps' lock, and the title's releases that forgot views. These counters showed that the slots made again, not the checks or the forgotten views, held the time. watch::TimedNs times spans in nanoseconds, since these add up from many of well under a microsecond. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
hackgods
marked this pull request as draft
November 26, 2026 19:04
Contributor
Author
|
Moving this back to draft. Taking the lock once per page halves the heap sync, but about 120 ms a frame is still left: the same ~39,000 slots are still made again every frame (about 22,000 left null, the rest copies of only ~1,700 distinct views), plus their per-slot bookkeeping. I'm working on that in this PR and will mark it ready with new in-game measurements once the remaining cost is gone or shown to be irreducible. |
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.
The heap sync was the largest single CPU cost of a world frame: 217 ms of a 557 ms frame on an M5 Pro, release build. This makes it about half as costly without changing what it does to any slot.
What it was spending the time on
Before every submission (about 21 a frame) the heap sync makes again the slots whose records the title copied into its shader-visible heaps as bytes. New diagnostics counters (below) split it per frame in the prologue world:
Of the ~39,000 made again, about 22,000 are left null and the rest are views of only about 1,700 distinct records. Making the views themselves (prepare plus the host view) took under 20 ms. About half the time was spent waiting for the heap's slot lock (
made). The heap sync took it once a slot, ~39,000 times a frame, while the title's threads recording draws take it to make their table slots.What changed
HostHeap::mirror_synceddoes for each slot exactly whatmirrordoes on the heap-sync path (for_draw == false), but takes the slot lock once for a page's slots instead of once a slot:mirrordoes.mirror.mirrorasks withview_at.mirror's null path and its making of a slot move intounmake_lockedandmake_locked, which both paths use, so the per-slot logic exists once.heap sync per frame:line with the split above (SyncPages,SyncFast,SyncNoView,SyncChecked,SyncUnverified,SyncMade, their nanosecond times,ViewsForgot).watch::TimedNstimes in nanoseconds, because these spans are well under a microsecond each and add up.Measured in the game
M5 Pro, 64 GB, macOS 27.2.1, CrossOver 26.3 Wine, D3DMetal 4.0 beta 3, Series X. Every run used the same save (the prologue) and key script, with
VICTORY_PATCH_MASKED=all VICTORY_FAULT_TRACKING=1 VICTORY_NO_HANG_WATCHDOG=1 VICTORY_STEP_OVER=pooland no GPU timing. Numbers are medians of the 5 s renderer reports with 500+ draws, from one minute after the world appears.One diagnostics binary, with a temporary switch to turn the batching on and off, run interleaved (off, on, on, off):
Release builds of
mainand of this branch, interleaved (main, branch, branch, main), 6 min each:mainbf99e72, run 1mainbf99e72, run 4Frame times vary a lot from run to run on this Mac: run 2 matches run 1, and run 4 had a slow phase. The release build has no heap-sync counter, so these frame times mix in every other cost. In an earlier release pair timed around
sync_heaps(one run each), the heap sync went from 217 ms (204–224) to 126 ms (87–142) a frame.The picture is unchanged. No crashes, ended submissions, queue moves or Metal errors occurred in any run.
How tested
mainbf99e72:cargo test --workspace555 passed, 0 failed both times.tools/macos/test-wine.sh --workspace --no-fail-fast1,124 → 1,125 passed, 0 failed (the new test).a_slot_rewritten_while_a_heap_sync_prepares_is_left_as_written_last. The title clears a slot while the sync prepares its view, through the existingWHILE_PREPARINGhook; the slot must stay as the title left it, then be made once copied again.heap_syncs_make_the_slots_whose_records_changed,a_table_slot_rewritten_before_submission_refreshes_its_new_viewand the bindless tests pass unchanged.cargo clippy -p victory-gpu --all-targets --target x86_64-pc-windows-gnullvm -- -D warnings, with and without--features diagnostics, andcargo xtask policypass. Only changed lines are formatted.Tried and left out
made, so the heap sync passes by slots already made from their record. These are texture views left null and placed textures, whosereadyis 0. It cut the check step from 21–30 ms to 7.5–10 ms. The total was not better in either interleaved pair, though, and it adds a rule every writer ofmadewould have to keep, so it is not in this PR.Notes
🤖 Generated with Claude Code