Take the changed card copies from a queue, not from a walk of all of them #251

Open
github-bot wants to merge 1 commit from github-bot/gh-251 into main AGit
Owner

@⁠CristianCiubancan on GitHub · 2026-11-27 12:20 UTC · original
CristianCiubancan:perf/card-dirty-queue-v2 → main · +245 −29 · 1 files · 1 commits · draft

One commit on main at 6141601. A draft because it touches the lines #238 and #199 move (see Overlap).

What

card_dirty took a reference to every copy in the card's memory at every submission to find the few whose CPU side had changed. #192 made the look at each copy lock-free (has_dirty), but the walk still upgrades and drops a Weak for each of them.

What puts a range into a copy's dirty (card_changed_runs) now also puts the copy on a list, once (a queued flag beside has_dirty), and card_dirty goes through that list.

  • The copies come out in the order they were listed in, as the walk gave them (each remembers its place).
  • has_dirty, sent and has_sent are set and cleared exactly where they were, in the same order; the take is the same closure for both ways.
  • VICTORY_CARD_DIRTY_QUEUE=0 walks as before. VICTORY_AB=<s>,VICTORY_CARD_DIRTY_QUEUE does each in turn in one run; the walk clears the queue and each copy's queued as it goes, so switching loses no change (tested).
  • The copies let go are taken out of CARDED when it has doubled since they last were, since no walk does it at every submission any more.

Measured

RTX 5070 Ti 16 GB, Ryzen 7 9850X3D, 32 GB, Windows 11. Diagnostics build of this branch, Series S, -Machine 4070 -Windowed, VICTORY_PIPELINE_WORKERS=8. The same self-driven route as in #247, one run each way, a VICTORY_PROFILE window of 60 s at 10 ms in the world. Share of the submitting thread's samples:

VICTORY_CARD_DIRTY_QUEUE=0 default (queue)
in shadow::card_dirty 3.45 % 0.93 %
of that, in the walk (Vec::retain's closure) 3.41 % 0 %

That thread works about 50 ms a frame there, so about 1.3 ms a frame. On the earlier base (3da964a, before #192) the same comparison gave 2.88 % against 0.84 % and 0.64 %.

Frame times do not show a change this small: an alternation in one hand-played session on the earlier base (20 s phases, 17 world phases, a fit against draws) leaned 1.6 ms to the queue's side with a scatter of 4.8 ms between phases, and the two runs here differ by more than that the other way (medians 18.9 and 17.8 fps, the second with a slow stretch of the kind #247 describes). The profile is the evidence; I do not claim a frame-rate gain from it.

Overlap

  • #238 and #199 both move the CARDED.lock()...push(Arc::downgrade(&shadow)) lines, which this replaces with list_carded(&shadow). It merges cleanly with neither as they are. I am glad to rebase on whichever lands first, or to wait for both.
  • It does not touch host.rs, so not #247.

Limits

  • One PC, one card, one profiled run each way on this base.
  • The picture: nothing recorded. On the earlier base I played two sessions with it and saw nothing wrong; on this base only the self-driven runs, with no errors and no device loss.

Checks

Three new tests (card_dirty_tests): the queue gives what the walk gives, in the same order; a copy changed again is taken again; the two ways in turn lose nothing. All three fail with the push to the queue taken out. cargo test -p victory-gpu --locked --all-features -- --test-threads=1 passes (537). Clippy with and without --all-features is clean, and cargo xtask policy passes.

🤖 Generated with Claude Code

**@⁠CristianCiubancan** on GitHub · 2026-11-27 12:20 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/251) `CristianCiubancan:perf/card-dirty-queue-v2` → `main` · +245 −29 · 1 files · 1 commits · draft One commit on `main` at `6141601`. A draft because it touches the lines #238 and #199 move (see Overlap). ## What `card_dirty` took a reference to every copy in the card's memory at every submission to find the few whose CPU side had changed. #192 made the look at each copy lock-free (`has_dirty`), but the walk still upgrades and drops a `Weak` for each of them. What puts a range into a copy's `dirty` (`card_changed_runs`) now also puts the copy on a list, once (a `queued` flag beside `has_dirty`), and `card_dirty` goes through that list. - The copies come out in the order they were listed in, as the walk gave them (each remembers its place). - `has_dirty`, `sent` and `has_sent` are set and cleared exactly where they were, in the same order; the take is the same closure for both ways. - `VICTORY_CARD_DIRTY_QUEUE=0` walks as before. `VICTORY_AB=<s>,VICTORY_CARD_DIRTY_QUEUE` does each in turn in one run; the walk clears the queue and each copy's `queued` as it goes, so switching loses no change (tested). - The copies let go are taken out of `CARDED` when it has doubled since they last were, since no walk does it at every submission any more. ## Measured RTX 5070 Ti 16 GB, Ryzen 7 9850X3D, 32 GB, Windows 11. Diagnostics build of this branch, Series S, `-Machine 4070 -Windowed`, `VICTORY_PIPELINE_WORKERS=8`. The same self-driven route as in #247, one run each way, a `VICTORY_PROFILE` window of 60 s at 10 ms in the world. Share of the submitting thread's samples: | | `VICTORY_CARD_DIRTY_QUEUE=0` | default (queue) | |---|---|---| | in `shadow::card_dirty` | 3.45 % | 0.93 % | | of that, in the walk (`Vec::retain`'s closure) | 3.41 % | 0 % | That thread works about 50 ms a frame there, so about 1.3 ms a frame. On the earlier base (`3da964a`, before #192) the same comparison gave 2.88 % against 0.84 % and 0.64 %. Frame times do not show a change this small: an alternation in one hand-played session on the earlier base (20 s phases, 17 world phases, a fit against draws) leaned 1.6 ms to the queue's side with a scatter of 4.8 ms between phases, and the two runs here differ by more than that the other way (medians 18.9 and 17.8 fps, the second with a slow stretch of the kind #247 describes). The profile is the evidence; I do not claim a frame-rate gain from it. ## Overlap - #238 and #199 both move the `CARDED.lock()...push(Arc::downgrade(&shadow))` lines, which this replaces with `list_carded(&shadow)`. It merges cleanly with neither as they are. I am glad to rebase on whichever lands first, or to wait for both. - It does not touch `host.rs`, so not #247. ## Limits - One PC, one card, one profiled run each way on this base. - The picture: nothing recorded. On the earlier base I played two sessions with it and saw nothing wrong; on this base only the self-driven runs, with no errors and no device loss. ## Checks Three new tests (`card_dirty_tests`): the queue gives what the walk gives, in the same order; a copy changed again is taken again; the two ways in turn lose nothing. All three fail with the push to the queue taken out. `cargo test -p victory-gpu --locked --all-features -- --test-threads=1` passes (537). Clippy with and without `--all-features` is clean, and `cargo xtask policy` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`card_dirty` took a reference to every copy in the card's memory at
every submission to find the few whose CPU side had changed: about
3,400 copies and 38 to 59 submissions a frame on an RTX 5070 Ti, 3.4 %
of the submitting thread's samples in that walk.

What puts a range into a copy's `dirty` now also puts the copy on a
list, once (`queued`), and `card_dirty` goes through that list. The
copies come out in the order they were listed in, as the walk gave
them. `VICTORY_CARD_DIRTY_QUEUE=0` walks as before, and
`VICTORY_AB=<s>,VICTORY_CARD_DIRTY_QUEUE` does each in turn in one run.
The copies let go are taken out of the list of all of them when it has
doubled, since no walk does it at every submission any more.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 12:23:24 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 12:26 UTC · original

@⁠CristianCiubancan The profile moved card_dirty from 3.45% to 0.93% of the submitting thread, which isolates the benefit of replacing the walk. #238 is in main now. The next branch should preserve its publish-time bookkeeping when list_carded replaces the registration calls. The order and switch-over tests are the right checks for that rebase.

**@⁠TaynanGT** on GitHub · 2026-11-27 12:26 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/251#issuecomment-7218246285) @⁠CristianCiubancan The profile moved `card_dirty` from 3.45% to 0.93% of the submitting thread, which isolates the benefit of replacing the walk. #238 is in main now. The next branch should preserve its publish-time bookkeeping when `list_carded` replaces the registration calls. The order and switch-over tests are the right checks for that rebase.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/shadow.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/251/head:github-bot/gh-251'
git switch 'github-bot/gh-251'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-251'
git switch 'github-bot/gh-251'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-251'
git switch 'github-bot/gh-251'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-251'
git switch 'main'
git merge --squash 'github-bot/gh-251'
git switch 'main'
git merge --ff-only 'github-bot/gh-251'
git switch 'main'
git merge 'github-bot/gh-251'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.