Scratch buffer pool starvation causes excessive allocations and severe FPS degradation #930

Closed
opened 2026-11-28 14:30:25 +00:00 by github-bot · 8 comments
Owner

@⁠moduz87 on GitHub · 2026-11-28 09:15 UTC · original

Hello,

During independent performance testing, we identified a potential flaw in the scratch buffer pool implementation in host.rs, specifically in Spare::give().

When the pool reaches its capacity, newly returned buffers are discarded while older, potentially unused buffers remain cached.

Our measurements showed:

Approximately 415 MB/s of unnecessary buffer allocations.

Approximately 190,000 additional page faults per second.

Performance degradation to 7.5 FPS.

We implemented an eviction policy that removes the oldest cached buffers instead of rejecting newly returned ones.

Results under the tested conditions:

Average FPS: 7.5 → 14.1 (+88%).

P99 frame time: 221 ms → 81 ms.

Continuous buffer allocations eliminated at steady state.

The original behavior is still present in the latest host.rs snapshot we inspected.

We have a working experimental patch and benchmark results available. We would be happy to discuss the findings and contribute the fix.

**@⁠moduz87** on GitHub · 2026-11-28 09:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/930) Hello, During independent performance testing, we identified a potential flaw in the scratch buffer pool implementation in host.rs, specifically in Spare::give(). When the pool reaches its capacity, newly returned buffers are discarded while older, potentially unused buffers remain cached. Our measurements showed: Approximately 415 MB/s of unnecessary buffer allocations. Approximately 190,000 additional page faults per second. Performance degradation to 7.5 FPS. We implemented an eviction policy that removes the oldest cached buffers instead of rejecting newly returned ones. Results under the tested conditions: Average FPS: 7.5 → 14.1 (+88%). P99 frame time: 221 ms → 81 ms. Continuous buffer allocations eliminated at steady state. The original behavior is still present in the latest host.rs snapshot we inspected. We have a working experimental patch and benchmark results available. We would be happy to discuss the findings and contribute the fix.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-28 14:30:25 +00:00
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-28 09:15 UTC · original

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)

**@⁠github-actions[bot]** on GitHub · 2026-11-28 09:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/930#issuecomment-7237125779) 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)
Author
Owner

@⁠moduz87 on GitHub · 2026-11-28 09:16 UTC · original

This is not a crash report. We independently identified a performance issue in the scratch buffer pool, specifically in Spare::give() in host.rs.

We have already developed an experimental fix and measured its impact through comparative benchmarks.

Under the affected conditions, performance improved from 7.5 to 14.1 FPS, eliminating approximately 415 MB/s of unnecessary buffer allocations.

GPU: NVIDIA RTX 5070 Ti 16 GB.
CPU: AMD Ryzen 7 3800X.
RAM: 32 GB.

Would you be interested in reviewing our findings, benchmark logs and proposed patch?

**@⁠moduz87** on GitHub · 2026-11-28 09:16 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/930#issuecomment-7237135150) This is not a crash report. We independently identified a performance issue in the scratch buffer pool, specifically in Spare::give() in host.rs. We have already developed an experimental fix and measured its impact through comparative benchmarks. Under the affected conditions, performance improved from 7.5 to 14.1 FPS, eliminating approximately 415 MB/s of unnecessary buffer allocations. GPU: NVIDIA RTX 5070 Ti 16 GB. CPU: AMD Ryzen 7 3800X. RAM: 32 GB. Would you be interested in reviewing our findings, benchmark logs and proposed patch?
Author
Owner

@⁠kibagami-nc on GitHub · 2026-11-28 09:44 UTC · original

The code agrees with you. Once the kept bytes would pass the limit, Spare::give hands the returned chunk back to be freed, whatever the kept ones are. take asks only for a chunk of the exact size wanted, so kept chunks of a size nobody asks for any more just hold the room.

Two things narrow when it bites:

  • The limit is 1 GiB with VICTORY_KEEP_FREED on (the default). It is 128 MiB only while crate::residency::limited_host_ram() holds, that is with little free RAM.
  • The trim: with VICTORY_ALLOCATOR_TRIM=1 (on in the launchers), every 10 s the chunks kept and never taken since the last trim are freed.

So the churn should be worst under host-memory pressure, between two trims. Your 32 GB with the game's footprint would fit that. If your measurement has the card memory / private-bytes lines, they would show whether the 128 MiB limit was the one in force.

A pull request with your patch and the benchmark is the way to get it reviewed. The logs the bot asks for are meant for crash reports. A unit test of Spare makes it easy to check without the game, for example:

  1. a full pool;
  2. a give that evicts the oldest kept chunk instead of refusing the new one;
  3. a take that gets the new one back.

The existing Spare tests near the end of host.rs show the shape.

**@⁠kibagami-nc** on GitHub · 2026-11-28 09:44 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/930#issuecomment-7237437295) The code agrees with you. Once the kept bytes would pass the limit, `Spare::give` hands the returned chunk back to be freed, whatever the kept ones are. `take` asks only for a chunk of the exact size wanted, so kept chunks of a size nobody asks for any more just hold the room. Two things narrow when it bites: - **The limit** is 1 GiB with `VICTORY_KEEP_FREED` on (the default). It is 128 MiB only while `crate::residency::limited_host_ram()` holds, that is with little free RAM. - **The trim:** with `VICTORY_ALLOCATOR_TRIM=1` (on in the launchers), every 10 s the chunks kept and never taken since the last trim are freed. So the churn should be worst under host-memory pressure, between two trims. Your 32 GB with the game's footprint would fit that. If your measurement has the `card memory` / private-bytes lines, they would show whether the 128 MiB limit was the one in force. A pull request with your patch and the benchmark is the way to get it reviewed. The logs the bot asks for are meant for crash reports. A unit test of `Spare` makes it easy to check without the game, for example: 1. a full pool; 2. a give that evicts the oldest kept chunk instead of refusing the new one; 3. a take that gets the new one back. The existing `Spare` tests near the end of `host.rs` show the shape.
Author
Owner

@⁠ANDREANIADS on GitHub · 2026-11-28 10:09 UTC · original

I exercised Spare on 63b902fe in debug and optimized builds with synthetic chunk IDs on CPU. I filled the 128 MiB pool with 512 × 256 KiB chunks, called trim() to start the observation window, then ran 64 take/give cycles at 4 MiB. There were 0/64 reuse hits before the next trim and 63/64 afterward. The 256 KiB control got 64/64 hits at capacity.

One regression case for your patch: start with that same full pool and return one 4 MiB chunk. With oldest-first eviction, the 16 oldest 256 KiB chunks should leave, and the retained total should still be 128 MiB. An immediate trim() should release the remaining 496 old chunks (124 MiB) and leave the new 4 MiB chunk available to take. This checks the byte count and the trim window when a single return replaces multiple chunks.

**@⁠ANDREANIADS** on GitHub · 2026-11-28 10:09 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/930#issuecomment-7237711038) I exercised `Spare` on `63b902fe` in debug and optimized builds with synthetic chunk IDs on CPU. I filled the 128 MiB pool with 512 × 256 KiB chunks, called `trim()` to start the observation window, then ran 64 take/give cycles at 4 MiB. There were 0/64 reuse hits before the next trim and 63/64 afterward. The 256 KiB control got 64/64 hits at capacity. One regression case for your patch: start with that same full pool and return one 4 MiB chunk. With oldest-first eviction, the 16 oldest 256 KiB chunks should leave, and the retained total should still be 128 MiB. An immediate `trim()` should release the remaining 496 old chunks (124 MiB) and leave the new 4 MiB chunk available to `take`. This checks the byte count and the trim window when a single return replaces multiple chunks.
Author
Owner

@⁠jptorres96 on GitHub · 2026-11-28 13:59 UTC · original

@⁠ANDREANIADS Your regression case is in #973 as one_big_chunk_into_a_full_pool_and_the_trim_after_it, with the same numbers: 512 × 256 KiB fill a 128 MiB pool, trim(), then one 4 MiB chunk is given back. It checks that the 16 oldest leave, that 128 MiB stay kept, that the next trim() frees the other 496 (124 MiB), and that take(4 MiB) returns the new chunk. 456/456 victory-gpu tests pass on that branch.

**@⁠jptorres96** on GitHub · 2026-11-28 13:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/930#issuecomment-7240328350) @⁠ANDREANIADS Your regression case is in #973 as `one_big_chunk_into_a_full_pool_and_the_trim_after_it`, with the same numbers: 512 × 256 KiB fill a 128 MiB pool, `trim()`, then one 4 MiB chunk is given back. It checks that the 16 oldest leave, that 128 MiB stay kept, that the next `trim()` frees the other 496 (124 MiB), and that `take(4 MiB)` returns the new chunk. 456/456 `victory-gpu` tests pass on that branch.
Author
Owner

@⁠Robotniq on GitHub · 2026-11-28 21:40 UTC · original

A data point from an RTX 3070 Ti 8 GB / i7-13700F / 32 GB RAM (Windows 11, Series S, DLSS Quality, the title's ray tracing off), diagnostics build of a tree whose Spare/give_chunks code is the same as main's.

  • Who gets the 128 MiB bound: limited_host_ram() (residency.rs:93) compares ullTotalPhys, the total RAM, with 32 GiB. A "32 GB" PC reports about 31.8 GiB, so every PC with 32 GB or less runs with SPARE_MOST (128 MiB) for the whole run, however much RAM is free. Only PCs with more than 32 GiB get the 1 GiB bound.
  • As is (5-minute scripted runs, same save and route, 2 runs): 279,000 to 296,000 upload buffers made per run (146 to 157 GB). The spare sits at 128 MB (54 chunks) all run. "new memory waited for": 339,000 times, 55.5 s, longest 68 ms.
  • With the bound at 512 MiB (a local switch, like fxceless/victory-fork#1367's VICTORY_SCRATCH_SPARE_MB): 445 upload buffers per run, 351 MB spare, "new memory waited for" 40,000 times, 9.5 s, longest 47 ms. Scratch memory went from about 200 MB to about 395 MB. The minimum free RAM stayed about the same (~4 GB, with the game at ~21 GB). Median fps after the first minute: 25.3 against 24.7 and 24.9, which is inside this PC's run-to-run noise. Here the waits fall mostly on the list threads, which are not this PC's limit.

I did not test #973's eviction.

Measured with AI assistance (Claude Code); the runs were made on my machine.

**@⁠Robotniq** on GitHub · 2026-11-28 21:40 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/930#issuecomment-7246186276) A data point from an RTX 3070 Ti 8 GB / i7-13700F / 32 GB RAM (Windows 11, Series S, DLSS Quality, the title's ray tracing off), diagnostics build of a tree whose `Spare`/`give_chunks` code is the same as main's. - **Who gets the 128 MiB bound:** `limited_host_ram()` (`residency.rs:93`) compares `ullTotalPhys`, the *total* RAM, with 32 GiB. A "32 GB" PC reports about 31.8 GiB, so every PC with 32 GB or less runs with `SPARE_MOST` (128 MiB) for the whole run, however much RAM is free. Only PCs with more than 32 GiB get the 1 GiB bound. - **As is (5-minute scripted runs, same save and route, 2 runs):** 279,000 to 296,000 upload buffers made per run (146 to 157 GB). The spare sits at 128 MB (54 chunks) all run. "new memory waited for": 339,000 times, 55.5 s, longest 68 ms. - **With the bound at 512 MiB** (a local switch, like fxceless/victory-fork#1367's `VICTORY_SCRATCH_SPARE_MB`): 445 upload buffers per run, 351 MB spare, "new memory waited for" 40,000 times, 9.5 s, longest 47 ms. Scratch memory went from about 200 MB to about 395 MB. The minimum free RAM stayed about the same (~4 GB, with the game at ~21 GB). Median fps after the first minute: 25.3 against 24.7 and 24.9, which is inside this PC's run-to-run noise. Here the waits fall mostly on the list threads, which are not this PC's limit. I did not test #973's eviction. Measured with AI assistance (Claude Code); the runs were made on my machine.
Author
Owner

@⁠kalberts0089-hash on GitHub · 2026-11-29 09:23 UTC · original

@⁠moduz87 @⁠jptorres96 Data point for rebasing #973. Main (829188e9, the commit v2026.11.29.01 is built from) still has the refusing Spare::give, and #973 now conflicts with it in 5 hunks of host.rs.

The part that's easy to get wrong: main now drops chunks from the front of kept in two pressure paths. One is the new Spare::trim_to (crates/victory-gpu/src/host.rs:2911) and the other is the kept.remove(0) loop in trim_spare_chunks (host.rs:3216). Both update low, which #973 replaces with old. After the rebase, old has to go down by the number drained (old.saturating_sub(n)), not just be clamped to kept.len(). Example: 4 kept at a trim, 2 given back since, then pressure drops the 3 oldest. If old shrinks, the next trim frees [4]. If it is clamped, the trim frees [4, 5, 6], which is ANDREANIADS's bug coming back by another route.

The copy-source pool UPLOAD_SPARE has the same starvation, and #973 doesn't touch it. give_uploads uses the same refusing give (host.rs:3145). The 10 s trim only runs on SPARE/SPARE_SHARED, so this pool is drained only while residency::pressured() holds. Synthetic test: 1024 x 1 MiB chunks fill the 1 GiB pool, then 1000 take/give cycles at 2 MiB. The refusing give reused 0/1000. Oldest-first eviction reused 999/1000. I haven't measured how often this happens in play, and I can't run the game here.

**@⁠kalberts0089-hash** on GitHub · 2026-11-29 09:23 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/930#issuecomment-7253736291) @⁠moduz87 @⁠jptorres96 Data point for rebasing #973. Main (`829188e9`, the commit v2026.11.29.01 is built from) still has the refusing `Spare::give`, and #973 now conflicts with it in 5 hunks of `host.rs`. The part that's easy to get wrong: main now drops chunks from the front of `kept` in two pressure paths. One is the new `Spare::trim_to` (`crates/victory-gpu/src/host.rs:2911`) and the other is the `kept.remove(0)` loop in `trim_spare_chunks` (`host.rs:3216`). Both update `low`, which #973 replaces with `old`. After the rebase, `old` has to go down by the number drained (`old.saturating_sub(n)`), not just be clamped to `kept.len()`. Example: 4 kept at a trim, 2 given back since, then pressure drops the 3 oldest. If `old` shrinks, the next trim frees `[4]`. If it is clamped, the trim frees `[4, 5, 6]`, which is ANDREANIADS's bug coming back by another route. The copy-source pool `UPLOAD_SPARE` has the same starvation, and #973 doesn't touch it. `give_uploads` uses the same refusing `give` (`host.rs:3145`). The 10 s trim only runs on `SPARE`/`SPARE_SHARED`, so this pool is drained only while `residency::pressured()` holds. Synthetic test: 1024 x 1 MiB chunks fill the 1 GiB pool, then 1000 take/give cycles at 2 MiB. The refusing `give` reused 0/1000. Oldest-first eviction reused 999/1000. I haven't measured how often this happens in play, and I can't run the game here.
Author
Owner

@⁠trustno1-coder on GitHub · 2026-11-29 23:07 UTC · original

Closing this one: it was reported on v2026.11.28.02 or earlier, and a lot has changed since (crash fixes, memory, shaders, warm-up and speed).

If it still happens on v2026.11.29.05, please open a new issue with the newest play log from %LOCALAPPDATA%\victory\logs\ and crashes.log, and we'll look at it there.

**@⁠trustno1-coder** on GitHub · 2026-11-29 23:07 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/issues/930#issuecomment-7264216121) Closing this one: it was reported on v2026.11.28.02 or earlier, and a lot has changed since (crash fixes, memory, shaders, warm-up and speed). If it still happens on [v2026.11.29.05](https://github.com/trustno1-coder/VIctory-NVIDIA/releases/tag/v2026.11.29.05), please open a new issue with the newest play log from `%LOCALAPPDATA%\victory\logs\` and `crashes.log`, and we'll look at it there.
This discussion has been locked. Commenting is limited to contributors.
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.

Dependencies

No dependencies set

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