Keep retired resources in groups by submission stamp #463

Closed
github-bot wants to merge 660 commits from github-bot/gh-463 into main AGit
Owner

@⁠Indy2l on GitHub · 2026-11-30 01:44 UTC · original
Indy2l:retire-groups → main · +60177 −5428 · 206 files · 660 commits · closed without merging

Summary

retire and retire_resource keep what they let go in 16 shards, each sorted by the submission count the object waits for. When an entry arrived with a stamp below the shard's newest, insert_retired put it in the middle of the shard's one VecDeque. That moves every newer entry along, under the shard's lock, and with bury_lag() keeping retired views for 16 or 64 more submissions, a shard holds thousands. It happens often: the stamp is STARTED + queued(), read from two counters, and HostHeap::keep retires the old resource of every slot whose resource changes, most of them from make_listed.

Each shard now keeps one group per stamp (Shard: a VecDeque<(u64, Vec<Retired>)>, oldest first), so a late entry is appended to its own group, and merge_retired_batch inserts each batched entry the same way. bury drains whole groups and drops them outside the lock as before. Up to 4 emptied groups per shard are kept for reuse, so a frame's groups don't grow from nothing.

Nothing about what is dropped, when, or in what order changes: by stamp, and within one stamp in the order retired, exactly as the single sorted queue held them.

RTX 3060 12 GB, i5-12400F, 16 GB, Series S, -Machine 3060 (3 workers)

A CPU profile (WPR, 60 s, sampled at 1 kHz) taken standing still at the window where the prologue first gives control, without touching the stick, before and after this change. Both builds were on fe7c6e5 + #395 (which only changes static sampler order, so the pipeline cache stays warm across launches and the two runs compare), with the play script's own -Machine 3060 settings. Share of all sampled stacks of victory.exe:

before (run 68) after (run 69)
VecDeque::insert from insert_retired 2.5% 0.0%
retire_resource in total 3.2% 0.6%

The after-build also had a second, local change (taking a reference only when a descriptor slot changes resource, the same as the keep_ref in #272), so the totals below are of both together: list translation (thin::Recording::run) fell from 1.78 to 1.62 cores, and the layer's own CPU per frame from about 308 to 285 ms, while the title's own code stayed at about 255 ms a frame. The frame rate at that spot did not change beyond the spread of runs (12.5 fps standing, 12.4 and 12.8 during the two profiles): those threads were not what the frame waited for there. The saving is CPU time, which should matter where the CPU is busier.

Verification

  • cargo clippy --locked --workspace --all-targets and the same with --all-features: clean.
  • cargo test --locked --workspace: no failures (victory-gpu lib 529 passed). In some parallel runs one of watch::tests::a_raw_copy_in_watched_memory_keeps_the_other_asked_ranges or host::refresh_tests::raw_title_copy_keeps_write_watch_and_resends_equal_bytes fails, on fe7c6e5 without this change as well (the flake of #443/#449); both pass alone and with --test-threads=1.
  • cargo test --locked --workspace --all-features -- --test-threads=1: no failures (victory-gpu lib 596 passed).
  • New tests in host::retire_batch_tests: groups_drop_in_the_order_of_one_sorted_queue (the drop order with late entries, a group inserted in the middle, a batch, and reused groups) and groups_let_go_what_the_single_queue_did (the old queue, kept in the test as it was, against the new shards over 200 random sequences of in-order, late and batched retirements and partial buries: the same entries let go at every bury, in the same order). With the group insert changed on purpose to put a late entry first, the second test fails. a_late_batch_does_not_hide_eligible_retirements is kept, adapted to the new type.
  • cargo run -p xtask --locked -- policy: 322 files ok. git diff --check: clean.
  • Runs: scripts\play.ps1 -Machine 3060 -Console series-s -Windowed -More @{VICTORY_OUTPUT='1920x1080'; VICTORY_UPSCALER='6'; VICTORY_RENDER_SCALE='0.5'} on the build described above, the prologue route with a stand-still of about 4 minutes at the window, wpr -start CPU -filemode for 60 s during it. No difference in the picture was noticed while playing, and none is expected: no object is let go at a different time. The profiles were taken on fe7c6e5 + #395 rather than plain fe7c6e5 because on plain fe7c6e5 this PC recompiles a varying set of static-sampler pipelines at each launch (#423), which would still be running at that spot in some runs. Recordings stay local.

🤖 Generated with Claude Code

**@⁠Indy2l** on GitHub · 2026-11-30 01:44 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/463) `Indy2l:retire-groups` → `main` · +60177 −5428 · 206 files · 660 commits · closed without merging ## Summary `retire` and `retire_resource` keep what they let go in 16 shards, each sorted by the submission count the object waits for. When an entry arrived with a stamp below the shard's newest, `insert_retired` put it in the middle of the shard's one `VecDeque`. That moves every newer entry along, under the shard's lock, and with `bury_lag()` keeping retired views for 16 or 64 more submissions, a shard holds thousands. It happens often: the stamp is `STARTED + queued()`, read from two counters, and `HostHeap::keep` retires the old resource of every slot whose resource changes, most of them from `make_listed`. Each shard now keeps one group per stamp (`Shard`: a `VecDeque<(u64, Vec<Retired>)>`, oldest first), so a late entry is appended to its own group, and `merge_retired_batch` inserts each batched entry the same way. `bury` drains whole groups and drops them outside the lock as before. Up to 4 emptied groups per shard are kept for reuse, so a frame's groups don't grow from nothing. Nothing about what is dropped, when, or in what order changes: by stamp, and within one stamp in the order retired, exactly as the single sorted queue held them. ## RTX 3060 12 GB, i5-12400F, 16 GB, Series S, `-Machine 3060` (3 workers) A CPU profile (WPR, 60 s, sampled at 1 kHz) taken standing still at the window where the prologue first gives control, without touching the stick, before and after this change. Both builds were on `fe7c6e5` + #395 (which only changes static sampler order, so the pipeline cache stays warm across launches and the two runs compare), with the play script's own `-Machine 3060` settings. Share of all sampled stacks of `victory.exe`: | | before (run 68) | after (run 69) | |---|---:|---:| | `VecDeque::insert` from `insert_retired` | 2.5% | 0.0% | | `retire_resource` in total | 3.2% | 0.6% | The after-build also had a second, local change (taking a reference only when a descriptor slot changes resource, the same as the `keep_ref` in #272), so the totals below are of both together: list translation (`thin::Recording::run`) fell from 1.78 to 1.62 cores, and the layer's own CPU per frame from about 308 to 285 ms, while the title's own code stayed at about 255 ms a frame. The frame rate at that spot did not change beyond the spread of runs (12.5 fps standing, 12.4 and 12.8 during the two profiles): those threads were not what the frame waited for there. The saving is CPU time, which should matter where the CPU is busier. ## Verification - `cargo clippy --locked --workspace --all-targets` and the same with `--all-features`: clean. - `cargo test --locked --workspace`: no failures (`victory-gpu` lib 529 passed). In some parallel runs one of `watch::tests::a_raw_copy_in_watched_memory_keeps_the_other_asked_ranges` or `host::refresh_tests::raw_title_copy_keeps_write_watch_and_resends_equal_bytes` fails, on `fe7c6e5` without this change as well (the flake of #443/#449); both pass alone and with `--test-threads=1`. - `cargo test --locked --workspace --all-features -- --test-threads=1`: no failures (`victory-gpu` lib 596 passed). - New tests in `host::retire_batch_tests`: `groups_drop_in_the_order_of_one_sorted_queue` (the drop order with late entries, a group inserted in the middle, a batch, and reused groups) and `groups_let_go_what_the_single_queue_did` (the old queue, kept in the test as it was, against the new shards over 200 random sequences of in-order, late and batched retirements and partial buries: the same entries let go at every bury, in the same order). With the group insert changed on purpose to put a late entry first, the second test fails. `a_late_batch_does_not_hide_eligible_retirements` is kept, adapted to the new type. - `cargo run -p xtask --locked -- policy`: 322 files ok. `git diff --check`: clean. - Runs: `scripts\play.ps1 -Machine 3060 -Console series-s -Windowed -More @{VICTORY_OUTPUT='1920x1080'; VICTORY_UPSCALER='6'; VICTORY_RENDER_SCALE='0.5'}` on the build described above, the prologue route with a stand-still of about 4 minutes at the window, `wpr -start CPU -filemode` for 60 s during it. No difference in the picture was noticed while playing, and none is expected: no object is let go at a different time. The profiles were taken on `fe7c6e5` + #395 rather than plain `fe7c6e5` because on plain `fe7c6e5` this PC recompiles a varying set of static-sampler pipelines at each launch (#423), which would still be running at that spot in some runs. Recordings stay local. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A resource retired with a stamp below the shard's newest was inserted into
the middle of one long queue, moving the thousands of newer entries along
under the shard lock (2.5% of CPU samples at a fixed spot, run68). Each shard
now keeps one group per stamp, so a late entry is appended to its group.
What is dropped, when, and in what order is unchanged; a test compares the
new shards with the old queue over random mixes of late, batched and
in-order retirements and partial buries.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-30 01:46:25 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-11-30 02:01 UTC · original · reviewed

Read the diff against main. The grouping keeps the old drop order:

  • Shard::insert appends to the stamp's own group, found at the back or by partition_point(at < stamp), and opens a new group at the sorted place only when the stamp has none. Within a stamp the order is the order retired, which is what the old partition_point(at <= stamp) insert gave.
  • merge_retired_batch still does a stable sort, then inserts each entry the same way. That matches the old split-and-merge, and the randomized groups_let_go_what_the_single_queue_did compares both over mixed in-order, late and batched retirements and partial buries.
  • bury still drops outside the shard lock, oldest group first. The second lock to hand back emptied groups happens only for shards that let something go.
  • Every other user of RETIRED goes through insert_retired or merge_retired_batch (retire, the late back paths, flush_retired), so none of them still assumes a flat queue.

Two small points, neither blocking:

  • A spare group keeps its capacity. After a frame that retired thousands into one stamp, up to 4 such vectors per shard stay allocated. That's bounded at 64 vectors in total, but could be worth a shrink_to cap if memory shows it.
  • A stamp missing in the middle still costs a VecDeque::insert, now among groups rather than entries, which is what removes the 2.5%.

CI is green; I didn't rerun the profile.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-11-30 02:01 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/463#pullrequestreview-6106075852) · **reviewed** Read the diff against main. The grouping keeps the old drop order: - `Shard::insert` appends to the stamp's own group, found at the back or by `partition_point(at < stamp)`, and opens a new group at the sorted place only when the stamp has none. Within a stamp the order is the order retired, which is what the old `partition_point(at <= stamp)` insert gave. - `merge_retired_batch` still does a stable sort, then inserts each entry the same way. That matches the old split-and-merge, and the randomized `groups_let_go_what_the_single_queue_did` compares both over mixed in-order, late and batched retirements and partial buries. - `bury` still drops outside the shard lock, oldest group first. The second lock to hand back emptied groups happens only for shards that let something go. - Every other user of `RETIRED` goes through `insert_retired` or `merge_retired_batch` (`retire`, the late `back` paths, `flush_retired`), so none of them still assumes a flat queue. Two small points, neither blocking: - A spare group keeps its capacity. After a frame that retired thousands into one stamp, up to 4 such vectors per shard stay allocated. That's bounded at 64 vectors in total, but could be worth a `shrink_to` cap if memory shows it. - A stamp missing in the middle still costs a `VecDeque::insert`, now among groups rather than entries, which is what removes the 2.5%. CI is green; I didn't rerun the profile. AI-assisted: yes
Author
Owner

@⁠Indy2l on GitHub · 2026-11-30 02:36 UTC · original

Thanks for reading it against main.

On the spare groups: the single VecDeque this replaces also kept its peak capacity per shard, and that peak held every live entry across all stamps, so the spares don't add a new kind of retention. The bound is small in numbers too: an entry is 24 bytes, so a spare that once held 20,000 entries is about 0.5 MB, and 64 of them at most about 30 MB. I'm looking at the process's memory on this 16 GB PC at the moment; if the spares show up there, I'll add a shrink_to cap in a follow-up.

On the middle insert: yes, a stamp with no group yet still goes in with VecDeque::insert, now moving the few groups of newer stamps instead of their thousands of entries.

**@⁠Indy2l** on GitHub · 2026-11-30 02:36 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/463#issuecomment-7267149378) Thanks for reading it against main. On the spare groups: the single `VecDeque` this replaces also kept its peak capacity per shard, and that peak held every live entry across all stamps, so the spares don't add a new kind of retention. The bound is small in numbers too: an entry is 24 bytes, so a spare that once held 20,000 entries is about 0.5 MB, and 64 of them at most about 30 MB. I'm looking at the process's memory on this 16 GB PC at the moment; if the spares show up there, I'll add a `shrink_to` cap in a follow-up. On the middle insert: yes, a stamp with no group yet still goes in with `VecDeque::insert`, now moving the few groups of newer stamps instead of their thousands of entries.
github-bot closed this pull request 2026-11-30 16:24:22 +00:00
Author
Owner

@⁠Indy2l on GitHub · 2026-11-30 16:23 UTC · original

Closing this: the new main (the NVIDIA rebuild) no longer has the cost it fixed. There, retire and retire_resource only push_back onto the calling thread's shard: no sorted insert among newer stamps and no batch merge, which is what moved thousands of entries under the lock in our profile. Thanks!

**@⁠Indy2l** on GitHub · 2026-11-30 16:23 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/463#issuecomment-7284600774) Closing this: the new main (the NVIDIA rebuild) no longer has the cost it fixed. There, `retire` and `retire_resource` only `push_back` onto the calling thread's shard: no sorted insert among newer stamps and no batch merge, which is what moved thousands of entries under the lock in our profile. Thanks!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.