GPU: let go of the idle snapshot pool, and shrink it under memory pressure #41
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/41"
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 TaynanGT/Vice-Tay-v2. Originally posted by welisonzika14-jpg on 2026-11-26T18:03:10Z.
@welisonzika14-jpg on GitHub · 2026-11-26 17:58 UTC · original
welisonzika14-jpg:fix/shadow-pool-idle→main· +156 −0 · 1 files · 1 commits · openProblem
shadow::POOLkeeps snapshot buffers for reuse, up to 512 MiB (give_back,KEPT). Onlygive_backever trims it, and only when another buffer comes back. So once snapshots stop, the last 512 MiB stays for the rest of the run, even when the host is short of memory. The largest buffer is always kept (kept > 0), so a single snapshot larger than 512 MiB stays too.Change
shadow::let_go_idlealready runs once a second fromhost::sweep. It now first callslet_go_idle_snapshots, which does this:host::ram_idle_msand 4 frames (the same rule as the loose windows), it frees all of it.residency::pressured()holds, it keeps only the smallest buffers, up to 32 MiB (POOL_PRESSURED_KEPT), and frees the rest, largest first.pooledandgive_backrecord the last use inPOOL_USED, as ahost::moment(). The freeing happens outside the lock, asgive_backalready does. The next snapshot after a trim is fresh memory, the same as every snapshot past the pool was before. With plenty of free RAM,ram_idle_msis 5 minutes, so normal play keeps the pool. The FPS cost should only show after an idle stretch or under pressure. I did not measure FPS in game.Tests
New
shadow::pool_tests:trimming_keeps_the_smallest_up_to_the_limittrimming_to_nothing_empties_the_poola_buffer_past_the_limit_goes_even_alonean_idle_pool_goes_and_a_pressed_one_shrinkspool_memory_load(#[ignore], run alone, because the pool is global):cargo test -p victory-gpu --lib shadow::pool_tests::pool_memory_load -- --ignored --nocapture --test-threads=1Load test on Windows 11 with an RTX 5070, in a debug build. It runs 256 snapshots of 1 to 32 MiB:
Results:
cargo test -p victory-gpu --lib: 401 passed, 0 failed, 37 ignored.cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo clippy -p victory-gpu --all-targets --all-features -- -D warnings: clean.Related: HumanlyDev/HUMAN#7 also bounds this pool, in a different way. This PR is written separately and is smaller. It touches only
shadow.rs.Written with AI help (Claude/Kiro).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.