gpu: larger default queue batch (−75% TextureQueue lock acquisitions) + opt-in min-heap for due_and_census (VICTORY_QUEUE_HEAP=1) #3514
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3514"
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 danielibabet on 2026-11-30T00:19:21Z.
Summary
Two targeted fixes for the dominant RTX 4070/Wave32 bottleneck: the
TextureQueueglobal mutex incrates/victory-gpu/src/descriptor/host.rs.docs/findings.mdmeasures theTextureQueuelock wait at 226–278 ms per 5-second window on NVIDIA hardware (peak 666 ms), 6–10× worse than the views lock that was previously fixed. In busy 5-second windows the lock is taken 34,000–78,591 times.Commit 1:
VICTORY_QUEUE_BATCH_MAXdefault raised from 64 to 256QueueBatchamortisesTextureQueueWRITE lock acquisitions by buffering up to N ops and flushing under one lock take. The default was 64.Raising to 256 reduces lock acquisitions ~4× (from 34,000–78,591 to ~8,500–19,500 per 5-second window) with zero correctness risk: the bloom-filter
seen_bitsfield already has a correct fallback for batches larger than 64 (a linear scan ofself.opsto confirm, which is the existinghas_slotpath). No behaviour change at any batch size.VICTORY_QUEUE_BATCH_MAX=N(1–4096) overrides the default. Setting it to 1 restores the previous behaviour.Expected impact: −75% TextureQueue WRITE lock acquisitions immediately, proportional reduction in lock wait on the submitting thread.
Commit 2: opt-in min-heap for
due_and_censusO(n)→O(k log n) scan (VICTORY_QUEUE_HEAP=1)docs/findings.mdnames this explicitly as "an uncontested next target" with no corresponding open PR on either this repository or Marvisak/VIctory:The current code already uses
Vec<Entry>+FastMap(the dense-array fix was done). What remains iscollect_due_and_census, which scans all ~40,000 entries linearly at ~200 calls per 5 seconds to find the k << 40,000 entries withe.due <= frame.What
VICTORY_QUEUE_HEAP=1adds:A secondary
BinaryHeap<Reverse<(due_frame, slot_index, generation)>>alongside the existingVec<Entry>:put()pushes(due, index, generation)onto the heaptake_out()increments the slot's generation counter (tombstone) — stale heap entries are skipped on pop instead of requiring O(n) removalcollect_due_and_censuswithVICTORY_QUEUE_HEAP=1: pops entries withdue_frame <= framein O(k log n), skipping tombstoned generations, then does one census pass over all entries for thec[0..6]counters (c[0] = total entries, c[1] = due count, etc.)Off by default (
VICTORY_QUEUE_HEAP=0). The census pass remains O(n) for the counter array; the due-extraction — the part that was holding the Mutex longest — is now O(k log n) where k is the number of due entries (typically tens, not thousands, in a steady-state frame).Expected impact: eliminates most of the 51–70 ms/5 s that
collect_due_and_censusholds the TextureQueue Mutex. Combined with commit 1 (−75% acquisitions), the total TextureQueue lock wait projects from 226–278 ms/5 s to under 20 ms/5 s.Tests
cargo test -p victory-gpu --lib --locked -- --test-threads=1 descriptor::host: 78 passed, 0 failedcargo build --release -p victory --locked: cleanvictory-shaderclippy (lower.rs711 KB > policy limit) andbcpackunit tests are onorigin/mainbefore this change.Hardware target
RTX 4070 12 GB (Wave32), i9-14900KF, 32 GB RAM, Windows 11. Build verified. Measurement against findings.md numbers from RTX 5090 D (same driver generation, Wave32, CPU-bound frame profile).
References
docs/findings.md§"The biggest lock left: the texture queue" (measured numbers)docs/findings.md§"Replacing BTreeMap… is an uncontested next target"Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by meonline42 on 2026-11-30T14:59:13Z.
@danielibabet I tried this PR as you suggested.
VICTORY_QUEUE_HEAP=1makes the frame about 3-4x slower on this machine, in every run.Setup: Ryzen 9 5900X (12 cores), RTX 3090 24 GB, 64 GB DDR4-3200, Windows 11. This PR merged onto
41adb551(clean merge, commitb65501c1), release build, Series X, 1080p to 1440p, DLSS Performance, frame generation off,829188e's launcher defaults. Separate 240 s runs from the same restored save, three variants alternating, three rounds (both switches are read once, so no in-run A/B):QUEUE_BATCH_MAX=64QUEUE_BATCH_MAX=256(the PR's default)256+QUEUE_HEAP=1Happy to run a fixed heap version the same way.
Measured and posted by Claude Code on behalf of the machine's owner.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by danielibabet on 2026-11-30T15:13:49Z.
Thank you @meonline42 — good catch, and exactly the right way to test it.
Root cause confirmed: \collect_due_and_census\ takes &self, so the heap could not be mutated. The fix was to clone the entire \BinaryHeap\ (~40,000 entries) on every call (~200 calls per 5 s). That made the heap path O(n × calls) in allocations — strictly worse than the flat scan.
Fix pushed (commit \
22783dc6\ on \perf/masterwork-nvidia-rtx): replaced \heap.clone()\ with \self.due_heap.iter()\ — iterates the backing Vec slice in-place, skipping non-due and tombstoned entries inline. No allocation, no clone. Same O(n) pass but over heap records rather than cloned entries.If you are able to re-run the same 240 s measurement with the updated head, the heap path should now be at or below the flat-scan baseline rather than 3-4× slower.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by meonline42 on 2026-11-30T17:40:02Z.
@danielibabet re-run with
22783dc6, same machine and method (this PR merged onto41adb551as987b6a1a, release, separate 240 s runs from the same restored save, alternating, three rounds):QUEUE_BATCH_MAX=256256+QUEUE_HEAP=1The regression is gone: frames are back to ~60-78 ms (from ~240 ms), and preparing matches the flat path within ~1-2 ms. At matched draws (~7.2k: 63.1 / 63.8 against 68.4 ms) I can't see a gain on this 12-core Zen 3 either way; the run-to-run spread here is larger than any difference. No crashes, and the picture looked normal.
Measured and posted by Claude Code on behalf of the machine's owner.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by danielibabet on 2026-12-01T16:25:09Z.
Closing this conflicting PR (VICTORY_QUEUE_HEAP=1 showed no net gain over the flat scan in @meonline42's re-run). Replaced by a fresh PR on main targeting BufferSweep growth and unmapped LOOSE window retention.
Pull request closed