Reduce allocations and prefetch in fill and write-watch hot paths #478
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/readmet3xt-lab--foxhound!478
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@GValdezN on GitHub · 2026-12-02 15:29 UTC · original
GValdezN:perf-quick-wins→main· +1129 −296 · 13 files · 3 commits · openReduce 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
@tillo88 on GitHub · 2026-12-02 21:06 UTC · original
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.
@GValdezN on GitHub · 2026-12-03 01:36 UTC · original
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.
@BrenoMazini on GitHub · 2026-12-03 02:07 UTC · original
Opened it as (#527) thanks for offering to review.
@tillo88 on GitHub · 2026-12-03 03:44 UTC · original
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
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.