GPU: a list's small first scratch chunk may be a kept 4 MiB one; 512 MiB of spare chunks (follow-up to #1349) #1367

Merged
Ym1r1710 merged 1 commit from upstream-pr/1367 into main 2026-11-26 23:06:37 +00:00
Ym1r1710 commented 2026-11-26 18:54:53 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Ym1r1710 on 2026-11-26T18:54:53Z.


Follow-up to #1349. That issue was about where retired objects get dropped. This PR is about why there were so many expensive ones to drop in the first place.

What

Two changes to the shared list scratch chunks (take_chunk / give_chunks in host.rs):

  • A list's small first chunk (256 KiB) can be a kept 4 MiB one when no 256 KiB chunk is kept. take_chunk now returns the chunk with its real size, so the list uses the whole 4 MiB and gives it back as 4 MiB. Turn it off with VICTORY_SCRATCH_ANY_SIZE=0.
  • The bound on kept spares goes from 128 MiB to 512 MiB. Set it with VICTORY_SCRATCH_SPARE_MB.

Why

I traced the slow drops from #1349 by kind. Almost all of the expensive ones were scratch chunks: committed upload buffers whose last reference a descriptor slot held. On the balcony (Series S, RTX 5080) that was per frame:

  • about 35 chunks of 256 KiB, ~1 ms each to free;
  • about 12 chunks of 4 MiB, 2-2.5 ms each.

The spares sat at the 128 MiB bound for the whole run, and all of them were 4 MiB ones. Spare::take only returns an exact size match, so every small first chunk was made new. Meanwhile, chunks coming back past the bound were freed. The lists hold about 140 MB of chunks at once there, so 128 MiB was just short.

Measured

Measured on my build, not on this main. It is an older base with this fork's relay code (VICTORY_RELAY=2) plus the CGBJ patches, --console series-s, diag profile. RTX 5080, 7800X3D, 32 GB. Jason's balcony after the first mission, same camera every run, around world+696. Drops already on their own thread (like VICTORY_REAPER=1).

frame resources destroyed by drops
old behaviour (VICTORY_SCRATCH_ANY_SIZE=0 VICTORY_SCRATCH_SPARE_MB=128), 2 runs 63-84 ms 30-52 a frame
this change, 3 runs 52-56 ms 0 a frame

The first run after a rebuild or a restart was 58-60 ms with the change. Scratch memory went from about 270 MB to about 395 MB. The pictures look the same and there were no device removals.

On this main the code is the same as on my base (exact-size take, SPARE_MOST = 128 MiB), so I ported it as is. I haven't measured it on this main yet. It would be good if someone could do an A/B with the two variables above.

Notes

  • It costs up to ~512 MB more of the PC's memory in the worst case; on my run it was ~125 MB. If that is too much for 16 GB machines, the default could depend on RAM size.
  • host.rs is already over the 512 KiB asset policy limit on main, so the policy check will fail here until #1357 or #1361 is in.
  • cargo check -p victory-gpu passes. I didn't run the full test suite.
<!-- greyfinch-sync:fxceless/victory-fork:issue:5515598521 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1367). Originally posted by [Ym1r1710](https://github.com/Ym1r1710) on 2026-11-26T18:54:53Z. --- Follow-up to #1349. That issue was about where retired objects get dropped. This PR is about why there were so many expensive ones to drop in the first place. ### What Two changes to the shared list scratch chunks (`take_chunk` / `give_chunks` in `host.rs`): - **A list's small first chunk (256 KiB) can be a kept 4 MiB one** when no 256 KiB chunk is kept. `take_chunk` now returns the chunk with its real size, so the list uses the whole 4 MiB and gives it back as 4 MiB. Turn it off with `VICTORY_SCRATCH_ANY_SIZE=0`. - **The bound on kept spares goes from 128 MiB to 512 MiB.** Set it with `VICTORY_SCRATCH_SPARE_MB`. ### Why I traced the slow drops from #1349 by kind. Almost all of the expensive ones were scratch chunks: committed upload buffers whose last reference a descriptor slot held. On the balcony (Series S, RTX 5080) that was per frame: - about 35 chunks of 256 KiB, ~1 ms each to free; - about 12 chunks of 4 MiB, 2-2.5 ms each. The spares sat at the 128 MiB bound for the whole run, and all of them were 4 MiB ones. `Spare::take` only returns an exact size match, so every small first chunk was made new. Meanwhile, chunks coming back past the bound were freed. The lists hold about 140 MB of chunks at once there, so 128 MiB was just short. ### Measured Measured on my build, not on this main. It is an older base with this fork's relay code (`VICTORY_RELAY=2`) plus the CGBJ patches, `--console series-s`, diag profile. RTX 5080, 7800X3D, 32 GB. Jason's balcony after the first mission, same camera every run, around world+696. Drops already on their own thread (like `VICTORY_REAPER=1`). | | frame | resources destroyed by drops | |---|---|---| | old behaviour (`VICTORY_SCRATCH_ANY_SIZE=0 VICTORY_SCRATCH_SPARE_MB=128`), 2 runs | 63-84 ms | 30-52 a frame | | this change, 3 runs | 52-56 ms | 0 a frame | The first run after a rebuild or a restart was 58-60 ms with the change. Scratch memory went from about 270 MB to about 395 MB. The pictures look the same and there were no device removals. On this main the code is the same as on my base (exact-size `take`, `SPARE_MOST` = 128 MiB), so I ported it as is. I haven't measured it on this main yet. It would be good if someone could do an A/B with the two variables above. ### Notes - It costs up to ~512 MB more of the PC's memory in the worst case; on my run it was ~125 MB. If that is too much for 16 GB machines, the default could depend on RAM size. - `host.rs` is already over the 512 KiB asset policy limit on main, so the policy check will fail here until #1357 or #1361 is in. - `cargo check -p victory-gpu` passes. I didn't run the full test suite.
Proudnoob4 commented 2026-11-27 04:03:51 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Proudnoob4 on 2026-11-27T04:03:51Z.


Data point from porting #1367 onto Proudnoob4/VIctory-NVIDIA (nvidia-hybrid-v2, 17161c7) — RTX 4080 16 GB, i5-13600K, 32 GB RAM, Windows 10, Series S 540p, release build, three 600 s prologue runs (Diner -> Cell -> Hallway -> Common Room -> Office -> Store):

  • Compiled and ran cleanly with 0 device losses and 0 crashes across all three 600 s runs.
  • Combined with mimalloc (trustno1-coder#11) and cached HostHeap::gpu (KyleS98/034bdca), Common Room median jumped from 37.8 -> 41.8 fps (prep 20.8 -> 18.9 ms, peak 44.8 fps) and Office peaked at 47.4 fps (prep 17.3 ms) with VICTORY_KEEP_PAGES=0 keeping AvailMB min = 219–422 MB on 32 GB RAM (no memory regression from the 512 MiB spare cap).

Not an isolated single-switch A/B of #1367 alone, but confirms clean stability and no 32 GB RAM pressure on NVIDIA across a full 10-minute playthrough. Numbers only; AI-assisted.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7209489338 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1367#issuecomment-7209489338). Originally posted by [Proudnoob4](https://github.com/Proudnoob4) on 2026-11-27T04:03:51Z. --- Data point from porting #1367 onto `Proudnoob4/VIctory-NVIDIA` (`nvidia-hybrid-v2`, [`17161c7`](https://github.com/Proudnoob4/VIctory-NVIDIA/commit/17161c7)) — RTX 4080 16 GB, i5-13600K, 32 GB RAM, Windows 10, Series S 540p, release build, three 600 s prologue runs (Diner -> Cell -> Hallway -> Common Room -> Office -> Store): - Compiled and ran cleanly with **0 device losses** and **0 crashes** across all three 600 s runs. - Combined with `mimalloc` (`trustno1-coder#11`) and cached `HostHeap::gpu` (`KyleS98/034bdca`), Common Room median jumped from **37.8 -> 41.8 fps** (`prep 20.8 -> 18.9 ms`, peak **44.8 fps**) and Office peaked at **47.4 fps** (`prep 17.3 ms`) with `VICTORY_KEEP_PAGES=0` keeping `AvailMB min = 219–422 MB` on 32 GB RAM (no memory regression from the 512 MiB spare cap). Not an isolated single-switch A/B of #1367 alone, but confirms clean stability and no 32 GB RAM pressure on NVIDIA across a full 10-minute playthrough. Numbers only; AI-assisted.
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
fxceless/victory-fork!1367
No description provided.