Skip to content

perf(gpu): read a heap sync batch's stale slots once a page, not once a slot - #640

Merged
pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
Nick233x:perf/heap-sync-span-read
Nov 27, 2026
Merged

pragyaangaur merged 1 commit into
pragyaangaur:mainfrom
Nick233x:perf/heap-sync-span-read

Conversation

@Nick233x

Copy link
Copy Markdown
Contributor

What

HostHeap::mirror_synced_batch (the default fast heap sync from #439) re-read every stale slot's record under self.made with its own ReadProcessMemory call, to catch a title thread that rewrote the slot since the page snapshot. It now reads the span of the batch's stale slots once, under the same lock: a page at most, since sync_heaps passes a page's slots per call. Each slot is then compared within that copy. If the span can't be read whole (or is wider than 1 MiB), it falls back to reading slot by slot, as before.

Why

bench_sync_slots_1_5m_fast_vs_legacy showed the fast path slower than the legacy one on an M5 Pro (speedup=0.83–0.90x, where #439 reported 2.38x on an M5 Max). Running the fast path first gave the same result, so the order of the runs is not the cause. Under Wine each ReadProcessMemory is a kernel call of about 0.5 µs: 39,100 of them took 18–21 ms on their own, about 70 % of the batch.

The race check is unchanged: the read still happens under self.made, after prepare, and a write after it is caught by the next sync, as before.

Measured

Apple M5 Pro, CrossOver Wine + D3DMetal, release build, bench_sync_slots_1_5m_fast_vs_legacy (1.5M slots scanned, ~39,100 made again), 3 runs each:

fast legacy speedup
main 27–29 ms 23–26 ms 0.83–0.90x
this branch 10–13 ms 28–33 ms¹ 2.5–2.7x

¹ The legacy path is unchanged; the Mac was busier during these runs.

Not measured in the game. At the ~39,000 slots a world frame makes again (#409), this should save about 15–19 ms of heap sync per frame on Macs where the call costs what it does here.

Tests

  • WINEDLLOVERRIDES="d3d12,d3d12core,dxgi=b" tools/macos/test-wine.sh -p victory-gpu --no-fail-fast: 591 passed, 0 failed, 19 ignored. That includes fast_heap_sync_handles_placed_null_duplicates_forget_and_concurrent_rewrite, which covers the rewrite check.
  • cargo clippy -p victory-gpu --all-targets for x86_64-pc-windows-gnullvm, with and without --all-features, -D warnings: clean.

No game data, offsets or file names here.

🤖 Generated with Claude Code

… a slot

mirror_synced_batch re-read every stale slot's record under self.made with
its own ReadProcessMemory call, to catch a title thread that rewrote the slot.
Under Wine each call is a kernel call of ~0.5 us: 39,100 of them took 18-21 ms
alone on an M5 Pro, ~70 % of the batch, and made the default fast heap sync
slower than the legacy path in bench_sync_slots_1_5m_fast_vs_legacy (0.83-0.90x).

The span of a batch's stale slots (a page's at most) is now read once under the
same lock and each slot compared in that copy; a span that cannot be read whole
falls back to a read per slot, as before. The race check is unchanged: the read
is still under self.made, after prepare, and a later write is caught by the next
sync as before.

Benchmark (M5 Pro, CrossOver Wine + D3DMetal, release, 3 runs): fast path
27-29 ms -> 10-13 ms for 1.5M slots scanned and ~39,100 made again, 2.5-2.7x
the legacy path. Not measured in the game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@hackgods

Copy link
Copy Markdown
Contributor

This is the same change as #633 (opened about two hours earlier), so the maintainer only needs one of them. Both read the batch's stale records together under self.made and fall back to a slot at a time when the read fails, so the race check is the same.

Differences, for picking one:

The bench numbers agree: about 0.46 µs per kernel copy under Wine, and the fast path about 2.5x faster with the reads together. I'm fine with whichever the maintainer prefers.

@pragyaangaur
pragyaangaur merged commit d33da08 into pragyaangaur:main Nov 27, 2026
1 check passed
Nick233x pushed a commit to Nick233x/VIctory-macOS that referenced this pull request Nov 28, 2026
main's pragyaangaur#640 reads a heap sync batch's stale records once a page, always,
as VICTORY_HEAP_READ_ONCE did here (on by default since dd434a4): that one
is kept, and the switch, its test and its docs row go. bench_made_again
times the merged path and prints the split of making slots again. In
flight.rs, main's SUBMISSIONS_BEGUN store goes after the fence check here.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gdemontalivet added a commit to gdemontalivet/VIctory-macOS that referenced this pull request Nov 28, 2026
…ion (VICTORY_QUICK_SYNC)

Add opt-in VICTORY_QUICK_SYNC (default off; supports 1, maps, views) layered onto batched heap sync and VICTORY_CENSUS_FAST=1:

- Part A (census_maps.rs + bindless.rs): multiply-and-fold FoldHasher (Hashing) and hash-backed RangesMap replacing BTreeMap in bindless::Viewed when enabled, preserving UnorderedIndex / SnapshotCache (VICTORY_CENSUS_FAST=1), pragyaangaur#613 hull_generation invariance across interior view edits, deterministic BTreeMap-equivalent ordering in widened_writes_into when RangesMap is hash-backed, and sorting range copy keys before dedup in diagnostics.
- Part B (descriptor/host/quick.rs + descriptor/host.rs): resolve each unique buffer SRV, placed buffer SRV, or aligned CBV record once per synced 64 KiB page outside HostHeap::made (including 3-channel widening, raw_structured lowering, held source, stride, view address, and bindless::Seen), then stamp matching slots via StagingHeap templates, keep_batch, and Viewed::set_batch_resolved while preserving pragyaangaur#640 page-span live reads, pragyaangaur#618 deferred show-after, and SyncStat / VICTORY_VIEW_PROBE telemetry. Textures, UAVs, samplers, placed textures, and refused/edge-case views stay on the standard path.
- Add unit and live GPU equivalence tests comparing quick sync against standard sync across all view kinds, VICTORY_CENSUS_FAST=1, deterministic widened_writes_into ordering, and both Wine and native D3D12 (WARP) alignment/format rules.
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.

3 participants