gpu: keep the snapshot pool sorted; binary-search take/insert instead of scan + re-sort #3384
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3384
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3384"
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?
@borosf on GitHub · 2026-11-26 21:14 UTC · original
borosf:vibe/pool-scan-842ca5→main· +86 −32 · 1 files · 2 commits · openWhat
0dd0f3d(andrewpozdnakov7-jpg's combined resolution) taken asabc64683: one PR now carries the wholesnapshot-pool change.
takeis onepartition_pointplus a
removeof the smallest buffer that fits;give_backinserts at the partition point. This replacesthe linear scan on every take and the re-sort on every return.
main's retention —give_backkeeps the largest buffers up toPOOL_BYTES(512 MiB), unchanged.try_reserve_exactfails,takelogssnapshot allocation failed; freeing the idle pool, clears the idle pool, and reserves once more insteadof aborting the snapshot.
the_snapshot_pool_preserves_best_fit_and_orderbuilds aSnapshotPoolof its owninstead of driving the shared
POOL, so it no longer races the othershadow::teststhat take snapshots.Credits:
Co-authored-by: andrewpozdnakov7-jpg(the combined resolution,0dd0f3d) andCo-authored-by: desplmfao(the allocation retry, #2153) are both on the commit.Claimed on #1633 (pool maintenance follows the sweep claims).
Measurement (Windows 11 x64, B580, synthetic Vec pool of 2,000 buffers, debug build, 3 rounds)
Per snapshot segment per frame this removes the O(pool) scan and the O(pool log pool) sort under the global
POOLmutex.Verification (head
abc64683, Windows 11 x64, B580)cargo test -p victory-gpu --lib shadow:: -- --test-threads=1— 11 passed, 0 failed, includingshadow::tests::the_snapshot_pool_preserves_best_fit_and_ordercargo test -p victory-gpu --lib --no-fail-fast -- --test-threads=1— 230 passed, 2 failed, 1 ignored;the two are the known B580 baseline (#1744/#1829):
descriptor::host::tests::dynamic_slots_are_held_until_releasedandmemory::tests::lists_share_a_table_and_copies_keep_their_views-D warnings, default features and--all-featuresshadow.rs39 hunks =origin/mainbaseline (39)cargo xtask policy— 191 files okSynthetic tests only; no game data used.
@Dukestar69 on GitHub · 2026-11-26 21:29 UTC · original · approved these changes
LGTM — verified on RTX 5090 (Windows / D3D12) against
origin/main(63bcca4).cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 11 passed, 0 failed (includingthe_pool_stays_sorted_and_best_fit_without_resorting).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@fuzeofficlal on GitHub · 2026-11-26 21:41 UTC · original · approved these changes
Looks clean and preserves exact best-fit and
POOL_BYTESretention semantics.Verified all accesses to
POOLincrates/victory-gpu/src/shadow.rs(pooledat line 105,give_backat line 123, and the new test at line 1315): keepingPOOLdescending by capacity ensurespartition_point(|v| v.capacity() >= n).checked_sub(1)selects the smallest buffer that fits (remove(i)preserves the sorted order) andgive_backinserts in sorted order beforeretaintrims toPOOL_BYTES.Verification on
origin/main(63bcca43):cargo xtask policy: ok (191 files ok)cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics): cleancargo test --locked -p victory-gpu --features diagnostics -- shadow::tests::withVICTORY_D3D12_DEBUG=1: 10/10 passed on RTX 5090 (200 take/return cycles at pool size 2,000 in 1.52 ms) and 10/10 passed on WARP (1.56 ms)n = 0, duplicate capacities,n > max, andPOOL_BYTESoverflow eviction: passed.@passerbyyhx on GitHub · 2026-11-26 22:33 UTC · original
Independent Release check on Windows 11 26H2 / i9-14900HX (Rust 1.98.1, AC, Balanced). I compared
63bcca43with2b0d14cusing the realshadow::pooledandgive_backfunctions with pre-touched synthetic buffers. Each of 12 pairs used fresh processes and alternated run order. Each cell timed 40,000 take/return cycles after warming up.The 8-buffer timing ranges overlap. At 128 and 2,000 buffers the head was faster in every pair for both request patterns. Both revisions passed the same best-fit, miss, equal-capacity and exact-512-MiB retention checks. An oversized return emptied the pool on both revisions.
This measures the hot single-threaded pool cycle. It leaves title frame time and lock contention unmeasured. Synthetic fixture
AI-assisted with Codex.
@Jackster on GitHub · 2026-11-26 22:34 UTC · original
Windows 11,
63bcca4+ this PR, Radeon RX 7900 XTX:shadow::tests::the_pool_stays_sorted_and_best_fit_without_resortingby name: 1 passed.cargo test -p victory-gpu --lib: 232 passed / 0 failed / 1 ignored (unpatched63bcca4here: 231).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.Synthetic only. AI-assisted.
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 23:06 UTC · original
I resolved the
shadow.rsconflict between #33842b0d14cand #2153c21a054in0dd0f3d. The merge keeps sorted best-fit reuse and the 512 MiB retention policy, and releases idle buffers before retrying a failed fresh reservation.The original #3384 test shared the process-wide pool. One controlled peer take between the two length checks made it see 1,998 entries when it expected 1,999. The replacement uses its own pool and keeps the best-fit, sorted order, return and successful miss checks. All 11 shadow tests, strict Clippy in both configurations and asset policy passed.
Using a test-only allocator in a separate process, I rejected the first synthetic reservation. The combined code made two attempts, freed both idle buffers and returned the requested empty buffer. With a successful first reservation, there was one attempt and both idle buffers stayed.
@borosf, the combined branch is ready if you coordinate the overlapping change with @desplmfao. If you reapply the resolution or its pool regression, please retain the Git author or add
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.@rezioliver-collab on GitHub · 2026-11-27 02:58 UTC · original
I measured the shared pool under contention on an Apple M1 (Rust 1.98.1, optimized), comparing base
63bcca43with PR2b0d14c9. Four workers started together and each ran 1,024 take/return cycles through the production mutex, rotating requests across four prefilled size classes (1–4 KiB). Every take returned the expected capacity, and the final pool contained exactly the starting capacities on both revisions.Each time is median wall time divided by the cycles completed across all four workers. I alternated revision order across 12 pairs. At 128 and 512 buffers the improvement also held in every pair with one and two workers. The small pool showed no consistent gain.
AI-assisted with Codex.
@borosf on GitHub · 2026-11-27 06:38 UTC · original
Three independent verifications, all pointing the same way — thank you.
That is the shape the change predicts: the win is
partition_point/inserton a sorted vector replacing a full scan plus sort, so it grows with the pool and disappears when the pool is small enough for the scan to beat the search.On @andrewpozdnakov7-jpg's note about the combined branch and the overlapping change: I will not reapply that resolution without agreeing the shape with @desplmfao first, and if I do, the Git author stays or the
Co-authored-by:line goes in — the same rule as #3224.Synthetic fixtures only, no game data.
@desplmfao on GitHub · 2026-11-27 08:20 UTC · original · edited 2026-11-27 09:08 UTC
@borosf thanks for checking first. Yes, please take @andrewpozdnakov7-jpg's combined resolution (
0dd0f3d) into this PR: sorted best-fit,main's 512 MiB retention, and the retry from #2153 (free the idle pool and reserve once more when a fresh reservation fails). Then only one PR touchespooled/give_back, and his own-pool test fixes the shared-pool race in the original test as well. Once this PR carries the retry, I'll close #2153 in favour of it. @andrewpozdnakov7-jpg'sCo-authored-byshould stay as he asked.@borosf on GitHub · 2026-11-27 08:48 UTC · original
Done —
0dd0f3dis in asabc64683, so this PR now carries the whole snapshot-pool change in one place:takeis onepartition_point+remove,give_backinserts at the partition point (the linear scan and the per-return re-sort are gone)main's 512 MiB retention, unchangedtry_reserve_exactfails, it warns, clears the idle pool, and reserves once more instead of aborting the snapshotSnapshotPoolwithtake/give_back, andthe_snapshot_pool_preserves_best_fit_and_orderbuilds its own pool rather than driving the sharedPOOL, so it no longer races the othershadow::teststhat take snapshotsBoth
Co-authored-bytrailers are on the commit:andrewpozdnakov7-jpgfor the combined resolution anddesplmfaofor the retry. @desplmfao — you said no credit was needed for the 15 lines, but the request in this thread was to credit you too, so the trailer is on the commit; say the word and I will drop it.Verification at
abc64683(Windows 11 x64, Arc B580):shadow::11 passed / 0 failed including the new test; fullvictory-gpulib 230 passed, 2 failed, 1 ignored, the two being the known B580 baseline (#1744/#1829,dynamic_slots_are_held_until_releasedandlists_share_a_table_and_copies_keep_their_views); clippy clean with-D warningsfor default and--all-features; fmt gate onshadow.rs39 hunks =origin/mainbaseline;cargo xtask policy191 files ok.I also rewrote the three hunks of the combined resolution that rustfmt would have reformatted (
static POOL, thewarn!, and thecapacitiesclosure in the test) so the fmt gate stays at the baseline count — content unchanged. #2153 can be closed in favour of this one whenever you want.Synthetic tests only, no game data used.
@desplmfao on GitHub · 2026-11-27 09:07 UTC · original
@borosf thanks, that's exactly it, and the trailer is fine as it is. #2153 is closed in favour of this PR.
@desplmfao on GitHub · 2026-11-27 09:08 UTC · original · edited 2026-11-27 09:10 UTC
@borosf a correction to my earlier comment: please keep the
Co-authored-by: desplmfaotrailer. The "no credit needed" line was Claude's mistake (the AI assistant that drafts these comments for me), not something I asked for. Thanks for keeping it in anyway.@borosf on GitHub · 2026-11-27 10:50 UTC · original
Good — the
Co-authored-by: desplmfaotrailer is on the commit (abc64683), as isandrewpozdnakov7-jpg's, so nothing needs changing on my side. Thanks for the correction and for closing #2153 in favour of this one.Current state: head
abc64683, one file (crates/victory-gpu/src/shadow.rs), mergeable, CI green (2m43s).shadow::11/11 locally includingthe_snapshot_pool_preserves_best_fit_and_order; fullvictory-gpulib 230 passed / 2 failed / 1 ignored, the two being the known B580 baseline (#1744/#1829); clippy clean for default and--all-features; fmt gate 39 =origin/mainbaseline;cargo xtask policy191 files ok.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.