Reduce allocations and prefetch in fill and write-watch hot paths #478
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/478"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from readmet3xt-lab/foxhound. Originally posted by GValdezN on 2026-12-02T15:29:32Z.
Reduce allocations and prefetch in fill and write-watch hot paths; CCD pinning, journal sharding, async copy queue and enhanced barriers
Three commits on the submitting thread's critical path:
Commit 1: Prefetch + Vec::with_capacity
Prefetch in
Batch::fill(): the fill loop prefetches the next entry's source and destination addresses with_mm_prefetch(..., _MM_HINT_T0)one iteration ahead, in both the single-threaded path (< 96 fills) and the wide path (>= 96, dispatched tovictory-wide-Nworkers viawide_each). The loop uses indexed access (self.fills[i]) with.clear()at the end instead of.drain(..)to avoid iterator overhead.Vec::with_capacityon seven hot-path allocations inwatch.rs: each vector is sized to the element count known at construction —kernel_written,ask_aheadruns,ask_restwritten/extra,writes,written_ranges_after,guard_locked.SPLIT[7] (copies and fills) accounts for 4–8 ms/frame; SPLIT[0] (write-watch asking) accounts for 5–10 ms. Complements #460 (skip redundant
guard_ahead).Commit 2: Four gated features + batch unguard
VICTORY_CCD_PIN=1: pins the submitting thread and its helpers (victory-submit,victory-send,victory-prelude,victory-ask,victory-wide) to the last-level cache group (CCD) they start on, so they share one L3 on dual-CCD Ryzen processors.VICTORY_JOURNAL_SHARDS=1: splits the JOURNAL'swritten,written_fastandpartsmaps into 16RwLock-guarded shards (page % 16), with a separateRwLockfor the globalahead/keptstate. Readers lock one shard per page instead of the whole journal. Complements the summary bitmap (#472) and the striped VirtualProtect (#434).VICTORY_COPY_AHEAD=1: recordsCopyBufferRegioncalls on a dedicatedD3D12_COMMAND_LIST_TYPE_COPYqueue, so the GPU's copy DMA engine runs in parallel with the previous frame's rendering. The DIRECT queue does a GPU-side Wait on the copy fence before barriers and scatter dispatches.VICTORY_ENHANCED_BARRIERS=1: on GPUs that reportEnhancedBarriersSupported, emitsD3D12_BUFFER_BARRIERwith preciseSyncBefore/SyncAfterscopes instead of legacy transitions. Phase 1 covers buffer-only sites incard_steps.rsandhost.rs.Batch unguard (always on): contiguous blocks in
unguard()are merged into singleVirtualProtectcalls with per-block fallback when the range spans twoVirtualAllocregions.Commit 3: Enhanced barriers phase 2
Mechanically migrates 25 remaining single-barrier buffer transition sites across 8 files to
buffer_barrier(). Net −45 lines. The 15 remainingResourceBarriersites are all textures (back buffers, render targets, depth stencils) — left for phase 3.Compatibility
unguard()but reduce different costs (syscall count vs lock hold time). Will need merge reconciliation.protect_here/protect_alias/open_unlocked.cargo test -p victory-gpu: 620 passed, 0 failed.🤖 Generated with Claude Code
Imported from readmet3xt-lab/foxhound. Originally posted by tillo88 on 2026-12-02T21:06:05Z.
Replay-bench measurement: no measurable difference on v0.8.3.3
Measured: PR head
06376bfmerged onto release v0.8.3.3 (same code as main7dbcdcb), 2 measured runs (after a warm-up run that is not counted), against 3 runs of v0.8.3.3 without the PR, same route (~6.5 min).Mean fps: release 36.38, PR 36.80 (+1.2%). That is below the 2-3% we treat as a real change, so: no measurable difference on this route. Only 3 release runs so far, so the release's own spread is not established yet.
Crashes: none in the PR runs and none in the release runs (no host GPU failure, no device lost).
Note: two earlier release runs the same evening, with identical switches, were much slower for most of the route (6-9 fps average); the cause is not known yet and they are left out of the comparison above. No PR run fell into that state.
Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB, Windows 11; default
play-foxhound.ps1settings (Series X profile, 1440p, DLSS balanced, no frame generation), fullscreen, no frame cap.Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.
Imported from readmet3xt-lab/foxhound. Originally posted by GValdezN on 2026-12-03T01:36:27Z.
Thanks for the replay-bench run, @tillo88! The +1.2% is the closest to the noise threshold of the three PRs you tested — not enough to call a real change on this route, but the allocation reduction and prefetch work targets per-frame overhead that shows up more under sustained CPU pressure (slower CPUs, Wine/Proton, or heavier scenes with more copy spans) than on a 9800X3D at steady state.
@BrenoMazini's analysis on #472 confirms the same pattern: the submitting thread's time on fast hardware is dominated by kernel write-watch and copies, not the allocation/prefetch overhead these changes address. Still worth having as a zero-regression cleanup that trims the constant factors.
Imported from readmet3xt-lab/foxhound. Originally posted by BrenoMazini on 2026-12-03T02:07:27Z.
Opened it as (https://github.com/readmet3xt-lab/foxhound/pull/527) thanks for offering to review.
Imported from readmet3xt-lab/foxhound. Originally posted by tillo88 on 2026-12-03T03:44:42Z.
Replay-bench measurement with
VICTORY_JOURNAL_SHARDS=1: no measurable fps difference on v0.8.3.3; CPU prep higher in both runsFollow-up to the earlier measurement of this PR with default switches. Measured: PR head
06376bfmerged onto release v0.8.3.3 (same code as main7dbcdcb), withVICTORY_JOURNAL_SHARDS=1, 2 measured runs (after a warm-up run that is not counted), against 8 runs of v0.8.3.3 without the PR, same route (~6.5 min).Mean fps: release 36.60, PR 36.03 (-1.6%), one run inside the release's range and one below it: no measurable difference in frame rate. The CPU prep time per frame was higher in both runs (21.87 / 21.91 ms) than in any of the 8 release runs (19.08-20.15 ms); with only 2 runs this is an observation, not a settled result.
Crashes: none in the PR runs and none in the release runs (no host GPU failure, no device lost).
Config: RTX 5070 Ti 16 GB, Ryzen 7 9800X3D, 32 GB, Windows 11; default
play-foxhound.ps1settings (Series X profile, 1440p, DLSS balanced, no frame generation), fullscreen, no frame cap.Measured unattended on a replay bench (same save, recorded controller input); numbers and text prepared with Claude.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.