[pr-perf] Eliminate per-submission allocation churn and O(N^2) grouping in card_before, card_record, and send::take #2587
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2587"
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 steven-seagull27 on 2026-11-29T14:41:07Z.
Summary
Eliminates per-submission heap allocation churn and O(N²) compare-list grouping overhead on the GPU submission hot path (
Host::card_before,Host::card_record, andhost::send::{take, Own::record}) while preserving bit-identical command ordering, coalescing, batching, and barrier semantics.What Changed
Zero-copy
CardDeclared/CardLookedborrowing inHost::card_before(crates/victory-gpu/src/host.rs)card_takecloned every(Arc<Shadow>, Vec<(usize, usize)>)indeclaredjust to filter.carded(), and clonedpicked.lookedinto ownedVecs even on the synchronouscard_beforepath wherecard_recordconsumes them immediately on the same thread.CardDeclared<'a>andCardLooked<'a>(Borrowed/Owned) socard_beforeborrows directly from&[Declared]and&[picked::Range]whenever!picked::lands() || picked.written.is_empty(), whilecard_take(used by cross-threadHandoff) continues to produce an ownedCardTake<'static>.Allocation-free range normalization & O(N) flat compare-list batching in
Host::card_record(crates/victory-gpu/src/host.rs)normalized_rangeswhich fast-paths 0-range, 1-range, and already-sorted strictly disjoint slices (w[0] <= w[1] && w[0].1 < w[1].0) by returning the input slice directly with zero heap allocations, and otherwise sorts and coalesces in place inside a reusable thread-local scratchVec(eliminating both theranges.clone()and separatespansVec).groups.iter_mut().find(...)+ per-groupvec![idx]compare-list batcher withCardBatcher: a flat intrusive singly-linked node array (groups+nodes) with a consecutive-key fast path, linear scan for ≤8 distinct keys, and automaticHashMap<CardBatchKey, usize, BuildHasherDefault<AddressHash>>indexing beyond 8 distinct keys. Preserves exact first-seen group order and insertion order within each group with zero per-groupVecallocations.prepared_ranges, range normalization scratch, andCardBatchervia RAII-guarded thread-localCardRecordScratch(draining/clearing allArc<Shadow>s on exit and capping retained capacity at4096entries so outlier spikes are released). Also pre-reservesplan.rangesunderCARD_WORK.Flattened
runsand reusable scratch buffers inhost::send(crates/victory-gpu/src/host/send.rs)Copy.runs: Vec<(usize, u64, usize)>into a single contiguousPlanBuffers.runsbuffer indexed by(runs_start, runs_len)perCopy, recycled viaSPARE_PLANSonDrop(capped atMAX_SPARE_PLANS = 4,MAX_SPARE_COPIES = 4096,MAX_SPARE_RUNS = 16_384, and cleared insend::trim()under critical commit).work: Vec<(usize, &[(usize, usize)], usize)>allocation insend::takeby indexingchunk_plansdirectly insiderun_scatter.chunk_plans,moves,copy_pieces, andcopy_tasksvia thread-localTakeScratchGuard(withpack_copy_tasks_intofilling scratch directly, andstd::mem::takewhenVICTORY_SEND_BESIDE=1handsmovesoff to worker threads) and reusedfirst/lastD3D12_RESOURCE_BARRIERVecs inOwn::recordvia thread-localRecordScratchGuard(capacity-capped so spikes are not retained).Synthetic Release Microbenchmarks
Measured with:
Each benchmark runs 3,000 synthetic submissions (30 submissions/frame × 100 frames) comparing the exact previous allocation/grouping logic against the optimized path and asserting identical checksums across 3 repeated runs:
card_recordbookkeeping (150 declared copies + 200 compare items across 64 keys)send::takeplanning (150 dirty copies, mixed short/long runs +pack_copy_tasks)(In addition to the measured bookkeeping and planning gains above,
card_beforeeliminates per-submissionDeclaredArc<Shadow>/Vecclones andOwn::recordeliminates per-submission barrierVecallocations.)Verification
cargo test --locked -j 2 -p victory-gpu --lib -- send:: --test-threads=1: 4 passed, 0 failed (including new equivalence & capacity-cap testsplan_dirty_ranges_matches_reference_across_shapesandpack_copy_tasks_into_reuses_buffers_and_matches_reference).cargo test --locked -j 2 -p victory-gpu --lib -- host:: --test-threads=1: 216 passed, 0 failed (including new equivalence, fuzz, and capacity-cap testsnormalized_ranges_matches_reference_across_shapesandcard_batcher_matches_reference_grouping_and_order).cargo test --release --locked -j 2 -p victory-gpu --lib -- send:: --test-threads=1andnormalized_ranges card_batcher: all passed.cargo clippy --locked -j 2 -p victory-gpu --lib --tests: 0 new warnings inhost.rsorhost/send.rs.cargo check --locked -j 2 -p victory-gpu --lib --features diagnostics: 0 errors/warnings in touched code (note: pre-existing unrelated compile errors exist onmainincopystat.rs:1349andhost.rssubmittiming()shadowing under--features diagnostics).git diff --check: clean.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by erLCoder on 2026-11-29T18:57:58Z.
<html>
Hardware testing — RTX 5060 Ti 16 GB / Ryzen 5 3600
Tested PR #2587 (
90400203) on physical NVIDIA hardware.System configuration:
GPU: NVIDIA RTX 5060 Ti 16 GB
CPU: AMD Ryzen 5 3600 (6C/12T)
RAM: 32 GB DDR4-3200
OS: Windows 10 Enterprise 22H2
NVIDIA driver: 621.40
Series S profile, DLSS Quality, Frame Generation disabled
Pipeline workers: 3
DirectStorage workers: 4
Both PRs were tested independently on the same base, which includes PR #2578 and a local fix preventing D3D12 initialization during pipeline failure reporting.
Compared with the #2504 build, #2587 showed approximately 11.5% higher median FPS, lower CPU submission time, reduced GPU idle time, and noticeably fewer long frames despite a comparable draw-call count.
The game successfully reached gameplay without crashing during this test.
Limitations: This was a preliminary hardware comparison, not a controlled benchmark against unmodified upstream. The shader cache was warmer during the #2587 run, and the scenes were not frame-identical. Therefore, the measured difference cannot be attributed exclusively to this PR.
Nevertheless, the results are promising, particularly on an older six-core CPU. This optimization deserves further hardware testing.
Thanks for working on the CPU submission bottleneck!
</html>Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by steven-seagull27 on 2026-11-29T20:35:20Z.
Thanks @erLCoder for testing
#2587(90400203) on your Ryzen 5 3600 / RTX 5060 Ti setup and sharing the breakdown! Really glad to see lower CPU submission time, fewer >100 ms frames (87 -> 34), and 0 crashes / PSO failures on a 6-core CPU. Appreciate you noting the warm-cache / scene caveats too — additional controlled A/B runs onmainare always welcome.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by steven-seagull27 on 2026-11-30T00:18:45Z.
Rebased cleanly onto
origin/main(41adb551,v2026.11.29.05).Conflict resolution
crates/victory-gpu/src/host/send.rs: preserved#2509'sparallel_copy_workthreshold insend::take(passingscratch.0.moves.len(),summary.total_run_bytes, and!chunk_plans.is_empty()), keeping both#2509's many-small-runs parallelization and#2587's recycledTakeScratch/PlanBuffers.crates/victory-gpu/src/host.rs: auto-merged cleanly, preservingcard_beforeborrowing, flat intrusiveCardBatcher, and zero-allocnormalized_ranges.Verification
cargo test --locked -j 3 -p victory-gpu --lib -- send:: --test-threads=1: 5 passed, 0 failed (includingparallel_copy_threshold_requires_multiple_tasks,pack_copy_tasks_into_reuses_buffers_and_matches_reference, andplan_dirty_ranges_matches_reference_across_shapes).cargo test --locked -j 3 -p victory-gpu --lib -- host:: --test-threads=1: 218 passed (host::batch::/card_beforetests all passed; the 1 unrelatedhost::card_steps::tests::places_written_after_sending_are_learnedfailure under single-thread heap address reuse passes 1/1 in isolation).cargo check --locked -j 3 -p victory-gpu --lib --features diagnostics: passed.cargo clippy --locked -j 3 -p victory-gpu --lib --tests: 0 new warnings in touched files.git diff --check origin/main..HEAD: clean.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by steven-seagull27 on 2026-11-30T18:19:03Z.
Closing as merged — commit
90400203landed onmainvia81611478(Merge PR #2587). Thanks again to @erLCoder for the hardware testing and @trustno1-coder for merging!Pull request closed