Reduce lock/atomic contention on the ~88% no-op refresh fast path (21.3 ms/frame on 8-core CPU, GPU 52% busy) #1521
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 trustno1-coder/VIctory-NVIDIA. Originally posted by GreekNinja on 2026-11-28T21:12:17Z.
Motivation (from
923e38cgameplay telemetry)On an 8-core Ryzen 7 5700X + RTX 3060 12 GB (Series S, DLSS Ultra Performance), once OOM/residency stalls are eliminated, the GPU averages only 52.0% busy (45.4 ms/frame idle waiting behind the submitting thread's 49.8 ms/frame).
The single largest CPU cost on the submitting thread is
refreshes: 21.3 ms/frame across ~9,964 spans/frame (44 flushes), of which 8,823 spans (88.5%) areknown to copy nothing.Bottleneck in the current no-op path
When
spans.len() > FEW (256)(crates/victory-gpu/src/host.rs:9342-9374, 9488-9528):wide_each_from(shadow.rs:1947-1970) fans out acrosswide_threads() + 1(7 threads on 8C/16T).Shadow::nothing_new()(shadow.rs:4442-4476) locks two separate mutexes (self.copied.lock()L4460 +self.ranged.lock()L4474), then callswatch::nothing_new()(watch.rs:961-978), which acquires and releases the globalJOURNALRwLock(SRWLock atomic RMW) and linearly scansj.ahead.iter().any(...)(watch.rs:970).FLUSHES[2].fetch_add(1)(host.rs:9367, 9524) on a single shared cache line across all 7 worker threads.Concrete Proposal
wide_each_range(shadow.rs:1947): let each worker acquire oneJOURNAL.read()guard perVICTORY_WIDE_CHUNK(e.g. 16 spans) and accumulatelet mut noop = 0u64;locally before a singleFLUSHES[2].fetch_add(noop)— cutting cross-core SRWLock + atomic RMW contention by 16× (~16,500 fewer cross-core atomics/frame).rangedintocopied'sMutex(shadow.rs:45-50): halves mutex lock/unlock ops innothing_new().j.aheadsorted (watch.rs:453) and replace linear.iter().any(...)(watch.rs:865, 886, 970) withpartition_pointbinary search.draw.rs:3656-3742): when!roomand first uploads are disallowed (orused >= budget), check!host.texture_slot_made_from(index, handle)before callingmapped_bytes()(VirtualQuerykernel walk) so held slots skipVirtualQuery(currently 87–281 ms per 5 s + 91 ms recording-thread lock contention under!room).Note: This report/comment was generated and submitted automatically by an AI assistant analyzing real local play logs and source code on behalf of the user.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by AiToR51 on 2026-11-28T23:49:16Z.
A second data point from the same CPU, and an A/B of the switch that is already in the tree.
Host: Ryzen 7 5700X (8C/16T), RTX 3080 10 GB, 32 GB DDR4, driver 621.40, Windows 10 22H2, Agility SDK 1.620. Series X profile, 1440p, DLSS Quality. Build
32ecacfawith #43 reverted locally (#1435). Host memory pressure is on in both runs.Method: the same save at the same indoor spot (~4,900 draws/frame), standing still. Each run is a fresh start, measured in its last 2 minutes after several minutes in the spot. The values are medians of the per-second
preparing per framelines and the 5 s frame lines.VICTORY_WIDE_CHUNKunset)VICTORY_WIDE_CHUNK=16The log confirmed
chunk=16in the second run.Takeaways:
VICTORY_WIDE_CHUNK=16changes nothing measurable here. It only hands the spans to the threads 16 at a time. Each span still takes its own locks andJOURNALread and bumps the shared counter. So the cost seems to be in the per-span work, which is what your proposals 1-3 change (oneJOURNAL.read()and one counter update per chunk, one mutex, a sortedahead), not in how the spans are handed out.One caveat: a first run of the default build, taken yesterday right after the start, measured 57.6 ms a frame with the same 11.9 ms of refreshes. The frame time falls over the first minutes of a session, so short runs from just after the start aren't comparable. Refreshes stay at 11.6-13.6 ms the whole time.
I can run the same A/B on a branch with your proposals if one appears.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by GreekNinja on 2026-11-29T00:15:39Z.
Thank you @AiToR51 for the controlled Ryzen 7 5700X A/B! That
VICTORY_WIDE_CHUNK=16comparison is super valuable — it isolates the bottleneck directly to the per-spanJOURNAL.read()+ dual-mutex + sharedFLUSHES[2]atomic work rather than chunk dispatch overhead (and confirms the same ~9,900 spans / ~90% no-op shape across both Series S and Series X).Having your steady-state indoor A/B spot ready to test a branch implementing proposals 1–3 will be a huge help if someone picks this up!
Note: This comment was generated and submitted automatically by an AI assistant on behalf of the user.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kalberts0089-hash on 2026-11-29T08:00:50Z.
Checked where each proposal stands at
e1f2eb6, and microbenched the no-op path on its own (no game here, so this is synthetic).Status at main
e1f2eb6wide_each_from(crates/victory-gpu/src/shadow.rs:1990) still calls the closure once per index even withVICTORY_WIDE_CHUNK>1, and the worker path still doesFLUSHES[2].fetch_add(1)per span (crates/victory-gpu/src/host.rs:9484,:9641). That fits the A/B above whereVICTORY_WIDE_CHUNK=16changed nothing.rangedintocopied: already done on main in0174844("perf(gpu): share the shadow copy state lock"). It is nowcopied: Mutex<Copied>(shadow.rs:27-40,:60).Shadow::nothing_newtakes one mutex (shadow.rs:4512). Thependingmutex is skipped unlesshas_pendingis set (shadow.rs:4507, from2396eda).0174844is not in923e38c,32ecacfaor v2026.11.28.03, so none of the numbers in this thread include it.ahead: not done.watch.rs:1055is still a linearj.ahead.iter().any(..).aheadis a plainVec(watch.rs:205), set from sorted pieces inask_ahead(watch.rs:529) and then appended to inask_rest(watch.rs:854) with no sort. There is also a second global lock per span that the issue doesn't name:owned()takesOWNED.read()(watch.rs:1053,:140-143) whenever the range isn't published.mapped_bytes(draw.rs:3726) still runs before the!room/texture_slot_made_fromcheck (draw.rs:3777).Microbench
This is a throwaway
#[ignore]test in a worktree ofe1f2eb6. It builds N spans that are all no-ops, each with its ownMutex. Each span calls the realwatch::nothing_new(realJOURNAL,OWNEDandpublished()bits) through the realwide_each/wide_each_frompool, plus a sharedfetch_add. "Chunked" mimics proposals 1+3: oneJOURNAL.read()and onefetch_addper 16 spans, and apartition_pointlook into a sortedahead.Setup: i7-13700KF,
VICTORY_WIDE_THREADS=6(7 threads, what an 8C/16T host gets by default), one flush of 9,000 no-op spans. Each cell is the range of the median of 200 flushes over two runs:aheadentriesWith the default 9 threads on this 24-thread CPU, "as now, chunk 1" was 641-811 us.
What this shows:
ahead, sending pure no-ops to the threads is 2-3x slower than doing them on the submitting thread. With a longahead, the linear scan dominates and the threads help.refreshesfigure is something else. It isSPLIT[6], which collects the wall time of whole flushes (host.rs:9498,:9595) plus the one-at-a-time refreshes (:9385,:9540). That includesask_ahead's kernel askings, the texture refreshes indue(on the:9498path),Self::updatefor the ~10 % that do copy, and waiting for the threads. In game, cold caches and the title's own threads would push the no-op cost above these numbers, but I doubt by 15-30x. A timer around just thenothing_newcalls, or the length ofj.aheadat flush time, from a play log would settle it.Caveats: warm cache, idle machine, tiny
copiedvectors, and the coveringaheadrange placed last (the worst case for the linear scan).Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-30T15:42:24Z.
Closing this because it was opened before v2026.11.29.01, and a great deal has changed since then. The latest release is v2026.11.30.01.
If this still happens, or still applies, on the latest release, please open a new issue. For a bug, attach both logs from that run:
victory-nvidia-play-<date>-<time>-<number>.login%LOCALAPPDATA%\victory\logs\.%LOCALAPPDATA%\VIctory\data\7952987A\crashes.log, plus the newest.crash.login%LOCALAPPDATA%\VIctory\data\7952987A\temp\if there is one from that run.