perf: take the copies in the card's memory that changed from a list of their own #291

Manually merged
github merged 1 commit from github-bot/gh-291 into main 2026-11-26 14:23:02 +00:00 AGit
Owner

@⁠Skyfrye on GitHub · 2026-11-26 01:28 UTC · original
Skyfrye:nep/card-dirty-queue → main · +133 −18 · 1 files · 1 commits · merged 2026-11-26 14:21 UTC

Draft: the in-game A/B is pending (the change, its test and the profile it comes from are done).

Change

shadow::card_dirty (crates/victory-gpu/src/shadow.rs), called by Host::card_before at every submission, went through every copy in the card's memory (CARDED) to find those whose Card::flagged was up. Nearly all were not: the pass took no lock of theirs, but upgraded and dropped a Weak and swapped an atomic for each of the thousands of copies, about 59 times a frame in the world.

Now a copy goes into a list of its own (FLAGGED) when its flag goes up (Card::flag, from card_changed, card_changed_runs and copy_to_chunk), and when it is made flagged (note_carded). card_dirty takes that list; what it does with each copy is unchanged (transient windows' chunks, dirty ranges joined, the relay's sent notes). A copy flagged again while card_dirty runs is in the next call's list, as it was picked up by the next pass before. CARDED still lists every copy for the memory line; copies that are gone are taken off it in note_carded, each time its length reaches a power of two (64 and up), instead of in card_dirty.

Where this comes from: a 30 s Nsight Systems capture of the world (release build of main at 3e258c8, launcher fast set, 263 frames). On the title's submitting thread, card_dirty was 2.5 % of the time on the CPU (the Vec::retain over CARDED), with no waits.

Linked issue: none.

Verification

Windows 11 26300, Rust 1.98.1 (MSVC), on upstream main at 578098b (merges cleanly on c4c93bd), from third_party/victory:

cargo build --locked --release -p victory            -> Finished, no new warning
cargo test --locked -p victory-gpu --lib -- shadow:: -> 34 passed
cargo test --locked -p victory-gpu --lib             -> 184 passed, 3 failed, 3 ignored

The 3 failures are the same on main without this change (183 passed, 3 failed): descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others.

New test card_dirty_takes_only_the_copies_flagged_since (copies on the software adapter): a copy made flagged is taken by the first call; a changed copy is taken once with its ranges; nothing is taken when nothing changed; a copy changed twice is taken once with both ranges; a copy let go is passed over; and a copy whose flag and range were set without going through the list is not looked at. Revert check: with card_dirty going through all of CARDED again it fails (it takes that last copy too: left: [(b, [(0, 16)]), (c, [(0, 8)])]).

Pending: an A/B in the world. The frame rate of the world moved 10-15 % between runs of the same build in my A/B of #278 and #279 (where the player is, and whether the driver is still recompiling shaders in the background), more than a 2.5 % share of one thread; a profile of the submitting thread is the better check.

Oracle and test data

No game file. The profile numbers come from my own capture of my copy of the game; no game code, address or dump is in this PR.

Checklist

  • The PR covers a single reviewable behaviour (the copies that changed are taken from a list of their own).
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above (the in-game A/B is pending, said above).
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success. (Nothing unimplemented here.)
  • README: not touched.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: engine function names from a profile of the engine; no title code.
  • Code taken from another project: none.

AI assistance: written with Claude Code. Claude Opus 5.5 read the Nsight Systems capture, wrote the change and its test, and wrote this description.

🤖 Generated with Claude Code

**@⁠Skyfrye** on GitHub · 2026-11-26 01:28 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/291) `Skyfrye:nep/card-dirty-queue` → `main` · +133 −18 · 1 files · 1 commits · merged 2026-11-26 14:21 UTC **Draft: the in-game A/B is pending** (the change, its test and the profile it comes from are done). ## Change `shadow::card_dirty` (`crates/victory-gpu/src/shadow.rs`), called by `Host::card_before` at every submission, went through every copy in the card's memory (`CARDED`) to find those whose `Card::flagged` was up. Nearly all were not: the pass took no lock of theirs, but upgraded and dropped a `Weak` and swapped an atomic for each of the thousands of copies, about 59 times a frame in the world. Now a copy goes into a list of its own (`FLAGGED`) when its flag goes up (`Card::flag`, from `card_changed`, `card_changed_runs` and `copy_to_chunk`), and when it is made flagged (`note_carded`). `card_dirty` takes that list; what it does with each copy is unchanged (transient windows' chunks, `dirty` ranges joined, the relay's `sent` notes). A copy flagged again while `card_dirty` runs is in the next call's list, as it was picked up by the next pass before. `CARDED` still lists every copy for the memory line; copies that are gone are taken off it in `note_carded`, each time its length reaches a power of two (64 and up), instead of in `card_dirty`. Where this comes from: a 30 s Nsight Systems capture of the world (release build of `main` at `3e258c8`, launcher fast set, 263 frames). On the title's submitting thread, `card_dirty` was 2.5 % of the time on the CPU (the `Vec::retain` over `CARDED`), with no waits. Linked issue: none. ## Verification Windows 11 26300, Rust 1.98.1 (MSVC), on upstream `main` at `578098b` (merges cleanly on `c4c93bd`), from `third_party/victory`: ``` cargo build --locked --release -p victory -> Finished, no new warning cargo test --locked -p victory-gpu --lib -- shadow:: -> 34 passed cargo test --locked -p victory-gpu --lib -> 184 passed, 3 failed, 3 ignored ``` The 3 failures are the same on `main` without this change (183 passed, 3 failed): `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`. New test `card_dirty_takes_only_the_copies_flagged_since` (copies on the software adapter): a copy made flagged is taken by the first call; a changed copy is taken once with its ranges; nothing is taken when nothing changed; a copy changed twice is taken once with both ranges; a copy let go is passed over; and a copy whose flag and range were set without going through the list is not looked at. Revert check: with `card_dirty` going through all of `CARDED` again it fails (it takes that last copy too: `left: [(b, [(0, 16)]), (c, [(0, 8)])]`). Pending: an A/B in the world. The frame rate of the world moved 10-15 % between runs of the same build in my A/B of #278 and #279 (where the player is, and whether the driver is still recompiling shaders in the background), more than a 2.5 % share of one thread; a profile of the submitting thread is the better check. ## Oracle and test data No game file. The profile numbers come from my own capture of my copy of the game; no game code, address or dump is in this PR. ## Checklist - [x] The PR covers a single reviewable behaviour (the copies that changed are taken from a list of their own). - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above (the in-game A/B is pending, said above). - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. (Nothing unimplemented here.) - [x] README: not touched. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: engine function names from a profile of the engine; no title code. - [x] Code taken from another project: none. AI assistance: written with Claude Code. Claude Opus 5.5 read the Nsight Systems capture, wrote the change and its test, and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`card_dirty` went through every copy in the card's memory at every
submission (about 59 a frame in the world) to find the few whose flag was
up: in a 30 s Nsight Systems profile of the world that pass was 2.5 % of
the submitting thread's time.

A copy now goes into a list (`FLAGGED`) when its flag goes up, and
`card_dirty` takes that list. `CARDED` still lists every copy (for the
memory line); copies that are gone are taken off it when copies are made.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:09 +00:00
Author
Owner

@⁠KainanP on GitHub · 2026-11-26 10:32 UTC · original

Test report for #291 on three adapters.

Merges cleanly onto current main. Setup: current origin/main (c4c93bd) merged with this PR, Windows 11, cargo test --locked in third_party/victory. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is --features diagnostics + VICTORY_D3D12_WARP=1. victory-gpu runs with --test-threads=1.

victory-gpu --lib main main + #291
RTX 4060 Laptop 183 passed, main's 3 failed 184 passed, main's 3 failed
Intel UHD 183 passed, main's 3 failed 184 passed, main's 3 failed
WARP 196 passed, main's 3 failed 197 passed, main's 3 failed

"main's 3" = descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed, indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots, indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others. They fail on all three adapters on main too. card_dirty_takes_only_the_copies_flagged_since passes everywhere. No new failure. These are the same counts you give.

Notes from reading the diff:

  • A copy whose card is set after note_carded (or code that sets flagged without Card::flag) is never taken. The test pins that on purpose. A debug_assert! in card_dirty or a grep-able comment at flagged would keep later code from doing flagged.store(true) directly.
  • CARDED is now pruned only when its length hits a power of two ≥ 64. After a big drop it can hold many dead Weaks until the next doubling. That only affects the memory line, not correctness.

AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this.

**@⁠KainanP** on GitHub · 2026-11-26 10:32 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/291#issuecomment-7189500990) Test report for #291 on three adapters. Merges cleanly onto current main. Setup: current `origin/main` (c4c93bd) merged with this PR, Windows 11, `cargo test --locked` in `third_party/victory`. Adapters: RTX 4060 Laptop (DXGI 0), Intel UHD 8086:a78b (16-lane waves, no FP64), WARP. The hardware adapter is picked by name through a local, uncommitted test hook and confirmed in its log; WARP for victory-gpu is `--features diagnostics` + `VICTORY_D3D12_WARP=1`. victory-gpu runs with `--test-threads=1`. | `victory-gpu --lib` | main | main + #291 | |---|---|---| | RTX 4060 Laptop | 183 passed, main's 3 failed | 184 passed, main's 3 failed | | Intel UHD | 183 passed, main's 3 failed | 184 passed, main's 3 failed | | WARP | 196 passed, main's 3 failed | 197 passed, main's 3 failed | "main's 3" = `descriptor::host::tests::spans_say_the_next_start_and_the_lowest_level_viewed`, `indirect::tests::warp_card_fetch_copies_flagged_pieces_to_their_slots`, `indirect::tests::warp_card_patch_writes_the_masked_bytes_and_no_others`. They fail on all three adapters on main too. `card_dirty_takes_only_the_copies_flagged_since` passes everywhere. No new failure. These are the same counts you give. Notes from reading the diff: - A copy whose `card` is set after `note_carded` (or code that sets `flagged` without `Card::flag`) is never taken. The test pins that on purpose. A `debug_assert!` in `card_dirty` or a grep-able comment at `flagged` would keep later code from doing `flagged.store(true)` directly. - `CARDED` is now pruned only when its length hits a power of two ≥ 64. After a big drop it can hold many dead `Weak`s until the next doubling. That only affects the memory line, not correctness. _AI use: Claude Code (Claude Opus 5.5) ran the tests and wrote this._
github-bot referenced this pull request from a commit 2026-11-26 12:41:47 +00:00
github manually merged commit 38075b65b0 into main 2026-11-26 14:23:02 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.