Remap queue: compact a full queue at most every quarter of it (copy-back CPU cost since #2607) #3877

Closed
github-bot wants to merge 2 commits from github-bot/gh-3877 into main AGit
Owner

@⁠tikD1337 on GitHub · 2026-11-30 10:04 UTC · original
tikD1337:tik/remap-compact-every → main · +117 −22 · 1 files · 2 commits · closed without merging

What

Since #2607 a full RemapQueue sorts and joins its whole unpublished suffix (up to 32,768 ranges) at every recorded range, under the queue's lock. Outdoors the queue stays full of disjoint unpublished ranges (~300 landing pieces a frame, each its own 64 KiB block), so a compaction frees no room and the very next range compacts again.

This PR keeps #2607's compaction but spaces it out: a full queue compacts at most every quarter of its length (VICTORY_REMAP_COMPACT_EVERY, default limit / 4; 1 restores compacting at every range). In between, a full queue drops its oldest range, as it did before #2607. VICTORY_AB can flip the switch within one run.

One file, crates/victory-gpu/src/descriptor/host.rs, plus a unit test (remap_history_compacts_a_full_queue_at_most_every_quarter). #2607's own tests still pass unchanged.

Measured

RTX 4070 Ti SUPER (driver 621.01), Ryzen 5 7600, 32 GB, Windows 11; diagnostics build of 41adb551. Unattended runs standing in the open world from the same save, ~6-8k draws per frame, warm pipeline cache. The stage timers came from a local diagnostics patch, not part of this PR.

Per frame, on the thread that copies back (landing):

main 41adb551 this PR
remapped_ranges from landing jobs 7.34 ms 0.05 ms
guards opened or noted in landing 9.78 ms 0.44 ms
merging what was fetched (lock contention) 5.22 ms 1.40 ms
landing in all 27.5 ms 23.7 ms
submitting thread's submissions 45.5 ms 40.5 ms

Before #2607 (commit 1b84c02) the landing guard figure was 0.39 ms, so this brings it back to where it was. Compactions now run ~0.1 times per frame.

What it does not do

No FPS change. An in-run A/B (VICTORY_AB=20,VICTORY_REMAP_COMPACT_EVERY, 17 alternating 20 s phases, same scene) gave a median frame-time ratio of 1.009, which is noise. Outdoors the copy-back thread runs beside the submitting thread and is not on the frame's critical path; the render threads' list calls and the title's own CPU work are. So this is a CPU and lock-time saving (about one core's 10 ms a frame), not an FPS gain. It may matter more on CPUs with fewer cores.

Tests

  • cargo test --release --locked -p victory-gpu: 921 passed, 2 failed, both also failing on main without this change:
    • shader_cache::tests::every_switch_of_the_translator_is_in_the_key still lists VICTORY_SCALAR_SPLITS, which 1b4b6cd4 removed from the translator.
    • host::card_steps::tests::places_written_after_sending_are_learned fails only in the parallel run (passes 3/3 alone); unrelated to this file.
  • cargo clippy -p victory-gpu --all-targets (with and without --all-features): no warning in the changed lines. main has ~25-30 existing warnings, so -D warnings fails without this change too.
  • No game files, logs or captures in the PR.

AI-assisted (Claude Code): the measurements, the diagnosis and the change were made with an AI agent and checked on the machine above.

🤖 Generated with Claude Code

Update (interleaved-writes edge case)

  • Folded @⁠tyr0nsur's companion fix (c0e1710, original commit 99e2a92, preserving authorship): while compaction is on cooldown, RemapQueue::record checks up to the last 8 unpublished entries and coalesces overlapping/touching unpublished ranges instead of evicting published history.
  • Added remap_history_keeps_published_ranges_during_interleaved_writes.
  • Verified cargo test --locked -p victory-gpu descriptor::host (both default and --features diagnostics: 82 passed, 0 failed, 1 ignored) and cargo clippy --locked -p victory-gpu --all-targets.
**@⁠tikD1337** on GitHub · 2026-11-30 10:04 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3877) `tikD1337:tik/remap-compact-every` → `main` · +117 −22 · 1 files · 2 commits · closed without merging ## What Since #2607 a full `RemapQueue` sorts and joins its whole unpublished suffix (up to 32,768 ranges) **at every recorded range**, under the queue's lock. Outdoors the queue stays full of disjoint unpublished ranges (~300 landing pieces a frame, each its own 64 KiB block), so a compaction frees no room and the very next range compacts again. This PR keeps #2607's compaction but spaces it out: a full queue compacts at most every quarter of its length (`VICTORY_REMAP_COMPACT_EVERY`, default `limit / 4`; `1` restores compacting at every range). In between, a full queue drops its oldest range, as it did before #2607. `VICTORY_AB` can flip the switch within one run. One file, `crates/victory-gpu/src/descriptor/host.rs`, plus a unit test (`remap_history_compacts_a_full_queue_at_most_every_quarter`). #2607's own tests still pass unchanged. ## Measured RTX 4070 Ti SUPER (driver 621.01), Ryzen 5 7600, 32 GB, Windows 11; diagnostics build of 41adb551. Unattended runs standing in the open world from the same save, ~6-8k draws per frame, warm pipeline cache. The stage timers came from a local diagnostics patch, not part of this PR. Per frame, on the thread that copies back (landing): | | main 41adb551 | this PR | |---|---|---| | `remapped_ranges` from landing jobs | 7.34 ms | 0.05 ms | | guards opened or noted in landing | 9.78 ms | 0.44 ms | | merging what was fetched (lock contention) | 5.22 ms | 1.40 ms | | landing in all | 27.5 ms | 23.7 ms | | submitting thread's submissions | 45.5 ms | 40.5 ms | Before #2607 (commit 1b84c02) the landing guard figure was 0.39 ms, so this brings it back to where it was. Compactions now run ~0.1 times per frame. ## What it does not do **No FPS change.** An in-run A/B (`VICTORY_AB=20,VICTORY_REMAP_COMPACT_EVERY`, 17 alternating 20 s phases, same scene) gave a median frame-time ratio of 1.009, which is noise. Outdoors the copy-back thread runs beside the submitting thread and is not on the frame's critical path; the render threads' list calls and the title's own CPU work are. So this is a CPU and lock-time saving (about one core's 10 ms a frame), not an FPS gain. It may matter more on CPUs with fewer cores. ## Tests - `cargo test --release --locked -p victory-gpu`: 921 passed, 2 failed, both also failing on main without this change: - `shader_cache::tests::every_switch_of_the_translator_is_in_the_key` still lists `VICTORY_SCALAR_SPLITS`, which 1b4b6cd4 removed from the translator. - `host::card_steps::tests::places_written_after_sending_are_learned` fails only in the parallel run (passes 3/3 alone); unrelated to this file. - `cargo clippy -p victory-gpu --all-targets` (with and without `--all-features`): no warning in the changed lines. main has ~25-30 existing warnings, so `-D warnings` fails without this change too. - No game files, logs or captures in the PR. AI-assisted (Claude Code): the measurements, the diagnosis and the change were made with an AI agent and checked on the machine above. 🤖 Generated with [Claude Code](https://claude.com/claude-code) ### Update (interleaved-writes edge case) - Folded @⁠tyr0nsur's companion fix (`c0e1710`, original commit `99e2a92`, preserving authorship): while compaction is on cooldown, `RemapQueue::record` checks up to the last 8 unpublished entries and coalesces overlapping/touching unpublished ranges instead of evicting published history. - Added `remap_history_keeps_published_ranges_during_interleaved_writes`. - Verified `cargo test --locked -p victory-gpu descriptor::host` (both default and `--features diagnostics`: 82 passed, 0 failed, 1 ignored) and `cargo clippy --locked -p victory-gpu --all-targets`.
Since #2607 a full RemapQueue sorted and joined its whole unpublished
suffix at every recorded range. Outdoors the queue stays full of disjoint
unpublished ranges (some 300 landing pieces a frame in 64 KiB blocks), so a
compaction frees no room and the next range compacts again, under the
queue's lock. A full queue now compacts at most every quarter of its length
(VICTORY_REMAP_COMPACT_EVERY; 1 restores compacting at every range, and
VICTORY_AB can flip it) and drops its oldest range in between, as before.

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

@⁠tikD1337 on GitHub · 2026-11-30 10:11 UTC · original · edited 2026-11-30 12:16 UTC

Note on the CI failure: victory-gpu (the only crate touched by this PR) compiles cleanly under clippy. The workspace clippy failure is the pre-existing dead_code error on unwind_copy in crates/victory-loader/src/crash.rs:804 on main 41adb551.

**@⁠tikD1337** on GitHub · 2026-11-30 10:11 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3877#issuecomment-7275242003) · edited 2026-11-30 12:16 UTC Note on the CI failure: `victory-gpu` (the only crate touched by this PR) compiles cleanly under clippy. The workspace clippy failure is the pre-existing `dead_code` error on `unwind_copy` in `crates/victory-loader/src/crash.rs:804` on `main` `41adb551`.
Author
Owner

@⁠tyr0nsur on GitHub · 2026-11-30 10:15 UTC · original

I reproduced one case where throttling can discard useful remap history at 3d3d9a8. Fill most of the queue with ranges already seen by a fast heap, then alternate writes to two unpublished ranges. When the newer write overlaps the second-to-last entry and the sort is on cooldown, it can evict a published range. A lagging heap then falls back to rescanning every placed slot.

The companion patch looks among the last eight entries while throttling is active. It only joins unpublished overlapping or touching ranges and moves the result to the tail with the latest sequence. The 1 setting still runs the original compaction path for the A/B comparison.

Using the real 32,768-entry limit and 8,193 synthetic alternating 64 KiB writes, history drops went from 8,191 to 0 and the lagging snapshot remained available. An equally long disjoint trace still ran two full compactions before and after. The regression test covers both a lagging and a current cursor. Diagnostics descriptor tests passed 74 checks, with 7 targeted checks also passing on WARP. These are queue measurements from a synthetic fixture.

Companion commit

**@⁠tyr0nsur** on GitHub · 2026-11-30 10:15 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3877#issuecomment-7275343506) I reproduced one case where throttling can discard useful remap history at `3d3d9a8`. Fill most of the queue with ranges already seen by a fast heap, then alternate writes to two unpublished ranges. When the newer write overlaps the second-to-last entry and the sort is on cooldown, it can evict a published range. A lagging heap then falls back to rescanning every placed slot. The companion patch looks among the last eight entries while throttling is active. It only joins unpublished overlapping or touching ranges and moves the result to the tail with the latest sequence. The `1` setting still runs the original compaction path for the A/B comparison. Using the real 32,768-entry limit and 8,193 synthetic alternating 64 KiB writes, history drops went from **8,191 to 0** and the lagging snapshot remained available. An equally long disjoint trace still ran two full compactions before and after. The regression test covers both a lagging and a current cursor. Diagnostics descriptor tests passed 74 checks, with 7 targeted checks also passing on WARP. These are queue measurements from a synthetic fixture. [Companion commit](https://github.com/tyr0nsur/VIctory-NVIDIA/commit/99e2a924860677d99d7b531945e66ae2dc448e43)
Try the recent unpublished entries before a throttled full queue evicts retained history. Keep published ranges and per-heap cursors intact, and leave the every-range compaction comparison available.

Co-authored-by: Claude Opus 5.5 <[email protected]>
Author
Owner

@⁠tikD1337 on GitHub · 2026-11-30 13:57 UTC · original

Thank you @⁠tyr0nsur for catching that interleaved-writes edge case and writing the fix! Cherry-picked your commit 99e2a92 (c0e1710 on this branch, preserving authorship) into #3877. Verified both cargo test --locked -p victory-gpu descriptor::host (default and --features diagnostics) and cargo clippy --locked -p victory-gpu --all-targets pass cleanly on the updated branch.

**@⁠tikD1337** on GitHub · 2026-11-30 13:57 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3877#issuecomment-7280630646) Thank you @⁠tyr0nsur for catching that interleaved-writes edge case and writing the fix! Cherry-picked your commit `99e2a92` (`c0e1710` on this branch, preserving authorship) into #3877. Verified both `cargo test --locked -p victory-gpu descriptor::host` (default and `--features diagnostics`) and `cargo clippy --locked -p victory-gpu --all-targets` pass cleanly on the updated branch.
github-bot closed this pull request 2026-11-30 17:03:36 +00:00
Author
Owner

@⁠tikD1337 on GitHub · 2026-11-30 16:59 UTC · original

Closing as superseded by 223f22f0 on main (superhero-520 added compact_after cooldown backoff for the same RemapQueue compaction storm). Thank you again @⁠tyr0nsur for catching the interleaved-writes edge case and writing 99e2a92!

**@⁠tikD1337** on GitHub · 2026-11-30 16:59 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3877#issuecomment-7285548696) Closing as superseded by `223f22f0` on `main` (`superhero-520` added `compact_after` cooldown backoff for the same `RemapQueue` compaction storm). Thank you again @⁠tyr0nsur for catching the interleaved-writes edge case and writing `99e2a92`!

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!3877
No description provided.