Avoid temporary range allocations in single-range descriptor copies #1572

Closed
opened 2026-11-28 21:51:58 +00:00 by Damokles2 · 3 comments
Damokles2 commented 2026-11-28 21:51:58 +00:00 (Migrated from github.com)
Contributor

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Damokles2 on 2026-11-28T21:51:58Z.


The descriptor copy implementation currently constructs two temporary range vectors even when exactly one source range and one destination range are supplied.

A narrow single-range fast path can snapshot the existing range metadata into local values and reuse copy_simple, avoiding both temporary allocations while preserving the general multi-range path.

An experimental implementation has been evaluated using synthetic CPU workloads, focused Windows descriptor-copy tests, and an asset-independent D3D12 WARP smoke test.

Results:

  • All 12,233 differential cases passed.
  • Both focused Windows descriptor-copy tests passed.
  • The WARP sampler heap and mirroring smoke test passed.
  • All 18 eligible benchmark workloads eliminated two allocator calls and 32 requested bytes.
  • General-path allocation counts remained unchanged.

Representative synthetic full-copy timings:

  • Default-size single range: approximately 88 ns to 7 ns.
  • Single range containing 256 descriptors: approximately 124 ns to 44 ns.

A subsequent same-runner guard comparison did not reproduce the earlier 1×4 range slowdown. The largest source-first full-copy control slowdown was 0.702 ns. The both-zero-range control showed a repeatable 0.616 ns overhead.

The measurements concern synthetic CPU copies, not complete live heap and mirroring performance or gameplay FPS.

Hosted experimental validation:

I intend to prepare a narrow production implementation using the source-first guard, following the current contribution and claim procedure.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:6671567895 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/1572). Originally posted by [Damokles2](https://github.com/Damokles2) on 2026-11-28T21:51:58Z. --- The descriptor `copy` implementation currently constructs two temporary range vectors even when exactly one source range and one destination range are supplied. A narrow single-range fast path can snapshot the existing range metadata into local values and reuse `copy_simple`, avoiding both temporary allocations while preserving the general multi-range path. An experimental implementation has been evaluated using synthetic CPU workloads, focused Windows descriptor-copy tests, and an asset-independent D3D12 WARP smoke test. Results: - All 12,233 differential cases passed. - Both focused Windows descriptor-copy tests passed. - The WARP sampler heap and mirroring smoke test passed. - All 18 eligible benchmark workloads eliminated two allocator calls and 32 requested bytes. - General-path allocation counts remained unchanged. Representative synthetic full-copy timings: - Default-size single range: approximately 88 ns to 7 ns. - Single range containing 256 descriptors: approximately 124 ns to 44 ns. A subsequent same-runner guard comparison did not reproduce the earlier 1×4 range slowdown. The largest source-first full-copy control slowdown was 0.702 ns. The both-zero-range control showed a repeatable 0.616 ns overhead. The measurements concern synthetic CPU copies, not complete live heap and mirroring performance or gameplay FPS. Hosted experimental validation: - [[Windows and WARP validation](https://github.com/Damokles2/VIctory-NVIDIA/actions/runs/46190992198)](https://github.com/Damokles2/VIctory-NVIDIA/actions/runs/46190992198) - [[Same-runner guard comparison](https://github.com/Damokles2/VIctory-NVIDIA/actions/runs/46192578700)](https://github.com/Damokles2/VIctory-NVIDIA/actions/runs/46192578700) I intend to prepare a narrow production implementation using the source-first guard, following the current contribution and claim procedure. AI-assisted with OpenAI Codex.
github-actions[bot] commented 2026-11-28 21:52:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by github-actions[bot] on 2026-11-28T21:52:07Z.


Please attach both logs from the run that went wrong. Without them we can only guess. Paste %LOCALAPPDATA% into the address bar of File Explorer to get there.

  1. The play log, in %LOCALAPPDATA%\victory\logs\: the newest victory-nvidia-play-<date>-<time>-<number>.log (from victory.exe) or victory-nvidia-<date>-<time>.log (from the script launcher). The window shows its path at the start, on the line Log: ....
  2. The crash log: %LOCALAPPDATA%\VIctory\data\7952987A\crashes.log, and, if there is one from that run, the newest victory-<date>-<time>-<number>.crash.log in %LOCALAPPDATA%\VIctory\data\7952987A\temp\.

Also say which GPU, Windows version (10 or 11)

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246331655 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/1572#issuecomment-7246331655). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T21:52:07Z. --- Please attach both logs from the run that went wrong. Without them we can only guess. Paste `%LOCALAPPDATA%` into the address bar of File Explorer to get there. 1. The play log, in `%LOCALAPPDATA%\victory\logs\`: the newest `victory-nvidia-play-<date>-<time>-<number>.log` (from `victory.exe`) or `victory-nvidia-<date>-<time>.log` (from the script launcher). The window shows its path at the start, on the line `Log: ...`. 2. The crash log: `%LOCALAPPDATA%\VIctory\data\7952987A\crashes.log`, and, if there is one from that run, the newest `victory-<date>-<time>-<number>.crash.log` in `%LOCALAPPDATA%\VIctory\data\7952987A\temp\`. Also say which GPU, Windows version (10 or 11)
Damokles2 commented 2026-11-28 21:54:45 +00:00 (Migrated from github.com)
Author
Contributor

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Damokles2 on 2026-11-28T21:54:45Z.


/claim

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246363031 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/1572#issuecomment-7246363031). Originally posted by [Damokles2](https://github.com/Damokles2) on 2026-11-28T21:54:45Z. --- /claim
kalberts0089-hash commented 2026-11-29 08:00:52 +00:00 (Migrated from github.com)
Author
Contributor

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by kalberts0089-hash on 2026-11-29T08:00:52Z.


The two temporary Vecs are still built on current main, including in the single-range case. On my machine #1616 saves about 44-54 ns per single-range call. On the multi-range path the change was within noise.

Code at e1f2eb6: the ranges closure at crates/victory-gpu/src/descriptor.rs:2084-2096 collects each side into a Vec<(u64, u32)>. Lines 2100-2101 build both vectors on every call, including when src_ranges == dst_ranges == 1.

Merge/tests: #1616 (head 59dd62e) merges cleanly --no-ff onto e1f2eb6. cargo test --locked -p victory-gpu --lib gives 591 passed, 0 failed, 44 ignored, the same as the report on #1616. The only change on main since the 568c5e5 used there is a README edit.

Local timing. Setup: i7-13700KF, Windows 11, rustc 1.98.1, --release, default features (so the system allocator, not the diagnostics counting allocator). I wrote a throwaway #[ignore] test that puts main's copy (copied verbatim) and the PR's copy in the same binary. It does 21 alternating passes of 200k calls and reports the median ns per call. It is synthetic: no shader heaps are registered, so mirror/mirror_range find nothing and return. Each cell shows three separate runs, kind 0 (32-byte descriptors).

Case main #1616
1x1, null sizes (1 descriptor) 70.9 / 61.2 / 68.0 16.7 / 16.9 / 17.2
1x1, n=1 62.3 / 60.7 / 67.9 16.6 / 17.0 / 16.6
1x1, n=256 195.1 / 194.3 / 198.7 148.6 / 148.5 / 149.9
1 src range of 16 -> 4 dst ranges of 4 106.6 / 105.9 / 107.7 105.7 / 109.6 / 108.4
4 src ranges of 4 -> 1 dst range of 16 108.3 / 106.2 / 107.9 106.6 / 111.4 / 106.7
4x4, 4 each 107.4 / 107.1 / 108.9 106.9 / 110.2 / 107.8

Allocating and freeing two one-element Vec<(u64, u32)> alone measured 43.6 and 44.0 ns. That roughly matches the single-range saving.

On the multi-range cases the PR was 3-5 ns slower in the second run, which is similar to the +2 to +4.5 ns in the PR's hosted numbers. In the other two runs it was 0.5-1.7 ns faster, except +0.6 ns on 1->4 in the third. Other builds were sharing the CPU, so I can't separate the overhead from noise here. I discarded one earlier run that was heavily contended (~1.1 us/call on both sides).

I haven't tested the effect in a title (no game files).

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7252829531 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/1572#issuecomment-7252829531). Originally posted by [kalberts0089-hash](https://github.com/kalberts0089-hash) on 2026-11-29T08:00:52Z. --- The two temporary `Vec`s are still built on current main, including in the single-range case. On my machine #1616 saves about 44-54 ns per single-range call. On the multi-range path the change was within noise. **Code at e1f2eb6:** the `ranges` closure at `crates/victory-gpu/src/descriptor.rs:2084-2096` collects each side into a `Vec<(u64, u32)>`. Lines 2100-2101 build both vectors on every call, including when `src_ranges == dst_ranges == 1`. **Merge/tests:** #1616 (head 59dd62e) merges cleanly `--no-ff` onto e1f2eb6. `cargo test --locked -p victory-gpu --lib` gives 591 passed, 0 failed, 44 ignored, the same as the report on #1616. The only change on main since the 568c5e5 used there is a README edit. **Local timing.** Setup: i7-13700KF, Windows 11, rustc 1.98.1, `--release`, default features (so the system allocator, not the diagnostics counting allocator). I wrote a throwaway `#[ignore]` test that puts main's `copy` (copied verbatim) and the PR's `copy` in the same binary. It does 21 alternating passes of 200k calls and reports the median ns per call. It is synthetic: no shader heaps are registered, so `mirror`/`mirror_range` find nothing and return. Each cell shows three separate runs, kind 0 (32-byte descriptors). | Case | main | #1616 | |---|---:|---:| | 1x1, null sizes (1 descriptor) | 70.9 / 61.2 / 68.0 | 16.7 / 16.9 / 17.2 | | 1x1, n=1 | 62.3 / 60.7 / 67.9 | 16.6 / 17.0 / 16.6 | | 1x1, n=256 | 195.1 / 194.3 / 198.7 | 148.6 / 148.5 / 149.9 | | 1 src range of 16 -> 4 dst ranges of 4 | 106.6 / 105.9 / 107.7 | 105.7 / 109.6 / 108.4 | | 4 src ranges of 4 -> 1 dst range of 16 | 108.3 / 106.2 / 107.9 | 106.6 / 111.4 / 106.7 | | 4x4, 4 each | 107.4 / 107.1 / 108.9 | 106.9 / 110.2 / 107.8 | Allocating and freeing two one-element `Vec<(u64, u32)>` alone measured 43.6 and 44.0 ns. That roughly matches the single-range saving. On the multi-range cases the PR was 3-5 ns slower in the second run, which is similar to the +2 to +4.5 ns in the PR's hosted numbers. In the other two runs it was 0.5-1.7 ns faster, except +0.6 ns on 1->4 in the third. Other builds were sharing the CPU, so I can't separate the overhead from noise here. I discarded one earlier run that was heavily contended (~1.1 us/call on both sides). I haven't tested the effect in a title (no game files).
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
trustno1-coder/VIctory-NVIDIA#1572
No description provided.