gpu: remove hot-path scratch allocations in relay_merge, send::take, and refresh_front #498

Closed
tiadiff wants to merge 1 commit from upstream-pr/498 into main
tiadiff commented 2026-11-27 23:35:27 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tiadiff on 2026-11-27T23:35:27Z.


Problem

Three hot CPU paths allocate unnecessarily per piece / per submission:

  1. Shadow::relay_merge (crates/victory-gpu/src/shadow.rs): calls title.clone() on every differing 64 KiB piece.
  2. send::take (crates/victory-gpu/src/host/send.rs): iterates ranges twice (separately for runs and short-word count).
  3. Batch::refresh_front (crates/victory-gpu/src/host.rs): allocates a 2-element Vec via .collect::<Vec<_>>() for summed.

Change

  • Reuse a thread_local! Vec<u8> buffer in Shadow::relay_merge instead of title.clone().
  • Merge run collection and word counting into one loop in send::take.
  • Replace the 2-element Vec in Batch::refresh_front with a stack [u64; 2].

Pure refactor with no behavioral change (3 files changed, 25 insertions(+), 10 deletions(-)).

Verification

  • cargo test --release --locked -p victory-gpu --lib shadow:: (passed)
  • cargo xtask policy (290 files ok)
  • cargo build --release --locked -p victory (succeeded)

Part of the low-stutter patch stack tested in https://github.com/tiadiff/VIctory-NVIDIA-LowStutter.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5534484487 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/498). Originally posted by [tiadiff](https://github.com/tiadiff) on 2026-11-27T23:35:27Z. --- ### Problem Three hot CPU paths allocate unnecessarily per piece / per submission: 1. `Shadow::relay_merge` (`crates/victory-gpu/src/shadow.rs`): calls `title.clone()` on every differing 64 KiB piece. 2. `send::take` (`crates/victory-gpu/src/host/send.rs`): iterates `ranges` twice (separately for runs and short-word count). 3. `Batch::refresh_front` (`crates/victory-gpu/src/host.rs`): allocates a 2-element `Vec` via `.collect::<Vec<_>>()` for `summed`. ### Change - Reuse a `thread_local!` `Vec<u8>` buffer in `Shadow::relay_merge` instead of `title.clone()`. - Merge run collection and word counting into one loop in `send::take`. - Replace the 2-element `Vec` in `Batch::refresh_front` with a stack `[u64; 2]`. Pure refactor with no behavioral change (`3 files changed, 25 insertions(+), 10 deletions(-)`). ### Verification - `cargo test --release --locked -p victory-gpu --lib shadow::` (passed) - `cargo xtask policy` (`290 files ok`) - `cargo build --release --locked -p victory` (succeeded) Part of the low-stutter patch stack tested in https://github.com/tiadiff/VIctory-NVIDIA-LowStutter.
Machad3x commented 2026-11-28 01:27:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Machad3x on 2026-11-28T01:27:39Z.


Tested in a batch on an RTX 3080 Ti + Ryzen 7 5700X, 1440p, DLSS Quality, title ray tracing on (VICTORY_BVH_BUILDER=1), 240 s run into the prison cell scene. Batch: #516, #501, #498, #497, #532, #521.
Result: alive for the whole run, 61.5-63.9 ms/frame, 1 draw/frame dropped (not from this batch), no shader or pipeline refused.
No problem found in this PR.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7231681214 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/498#issuecomment-7231681214). Originally posted by [Machad3x](https://github.com/Machad3x) on 2026-11-28T01:27:39Z. --- Tested in a batch on an RTX 3080 Ti + Ryzen 7 5700X, 1440p, DLSS Quality, title ray tracing on (VICTORY_BVH_BUILDER=1), 240 s run into the prison cell scene. Batch: #516, #501, #498, #497, #532, #521. Result: alive for the whole run, 61.5-63.9 ms/frame, 1 draw/frame dropped (not from this batch), no shader or pipeline refused. No problem found in this PR.
Rafa7046 commented 2026-11-28 01:28:23 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Rafa7046 on 2026-11-28T01:28:23Z.


Measured on an RTX 5080 16 GB + Ryzen 9 9950X3D (Series X, 1440p, DLSS Performance, frame generation off, diagnostics build on 64d4931 with only this PR applied, pipelines made ahead with victory warm), same stretch each run: Lucia's arrest cutscenes, then Jason on the boat and a minute standing still.

Cutscenes, fps (median) Boat, fps preparing in the cutscenes
main, run 1 37.4 35.8 19.6 ms
main, run 2 35.0 34.7 21.4 ms
with #498 35.9 35.7 21.5 ms

Two runs of plain main differ by about 2.4 fps, so this is within the run-to-run spread on this machine: no measurable change in frame rate here, and no new warnings, faults or crashes in the log. On this card the frame is set by the submitting thread (about 21 ms of a 28 ms frame), which is probably why a saving of this size does not show.

Same machine and scene with and without the title's ray tracing: #535.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7231689546 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/498#issuecomment-7231689546). Originally posted by [Rafa7046](https://github.com/Rafa7046) on 2026-11-28T01:28:23Z. --- Measured on an RTX 5080 16 GB + Ryzen 9 9950X3D (Series X, 1440p, DLSS Performance, frame generation off, diagnostics build on `64d4931` with only this PR applied, pipelines made ahead with `victory warm`), same stretch each run: Lucia's arrest cutscenes, then Jason on the boat and a minute standing still. | | Cutscenes, fps (median) | Boat, fps | `preparing` in the cutscenes | |---|---|---|---| | `main`, run 1 | 37.4 | 35.8 | 19.6 ms | | `main`, run 2 | 35.0 | 34.7 | 21.4 ms | | **with #498** | **35.9** | **35.7** | **21.5 ms** | Two runs of plain `main` differ by about 2.4 fps, so this is within the run-to-run spread on this machine: no measurable change in frame rate here, and no new warnings, faults or crashes in the log. On this card the frame is set by the submitting thread (about 21 ms of a 28 ms frame), which is probably why a saving of this size does not show. Same machine and scene with and without the title's ray tracing: #535.
tiadiff commented 2026-11-28 01:40:55 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tiadiff on 2026-11-28T01:40:55Z.


Thanks for the feedback.
Obviously, this fix alone won't improve average FPS on high-end hardware, because the main bottleneck elsewhere (thread management) must be an order of magnitude higher

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7231842801 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/498#issuecomment-7231842801). Originally posted by [tiadiff](https://github.com/tiadiff) on 2026-11-28T01:40:55Z. --- Thanks for the feedback. Obviously, this fix alone won't improve average FPS on high-end hardware, because the main bottleneck elsewhere (thread management) must be an order of magnitude higher
tiadiff commented 2026-11-28 22:33:14 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tiadiff on 2026-11-28T22:33:14Z.


This PR was auto-closed by GitHub when the original fork was detached into standalone repo tiadiff/VIctory-NVIDIA-LowStutter.

I rebased the patch cleanly onto current main (d4b5d51) preserving the total_run_bytes/total_pair_words counters in host/send.rs and re-ran cargo test --release --locked -p victory-gpu --lib shadow:: (48 passed; 2 ignored) and --lib host:: (145 passed; 16 ignored). Related open PR touching send::take: #1345.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246816760 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/498#issuecomment-7246816760). Originally posted by [tiadiff](https://github.com/tiadiff) on 2026-11-28T22:33:14Z. --- This PR was auto-closed by GitHub when the original fork was detached into standalone repo `tiadiff/VIctory-NVIDIA-LowStutter`. I rebased the patch cleanly onto current `main` (`d4b5d51`) preserving the `total_run_bytes`/`total_pair_words` counters in `host/send.rs` and re-ran `cargo test --release --locked -p victory-gpu --lib shadow::` (`48 passed; 2 ignored`) and `--lib host::` (`145 passed; 16 ignored`). Related open PR touching `send::take`: #1345. - Branch: https://github.com/tiadiff/VIctory-NVIDIA-LowStutter/tree/pr/gpu-hotpath-allocs - Commit: https://github.com/tiadiff/VIctory-NVIDIA-LowStutter/commit/e1701ebe2441a176f7904b309e4ec9c9123891d5 - Direct patch (`git am`): https://github.com/tiadiff/VIctory-NVIDIA-LowStutter/commit/e1701ebe2441a176f7904b309e4ec9c9123891d5.patch

Pull request closed

Sign in to join this conversation.
No reviewers
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!498
No description provided.