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

Closed
tikD1337 wants to merge 2 commits from upstream-pr/3877 into main
tikD1337 commented 2026-11-30 10:04:46 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tikD1337 on 2026-11-30T10:04:46Z.


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.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5563095586 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3877). Originally posted by [tikD1337](https://github.com/tikD1337) on 2026-11-30T10:04:46Z. --- ## 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`.
tikD1337 commented 2026-11-30 10:11:00 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tikD1337 on 2026-11-30T10:11:00Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7275242003 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3877#issuecomment-7275242003). Originally posted by [tikD1337](https://github.com/tikD1337) on 2026-11-30T10:11:00Z. --- 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`.
tyr0nsur commented 2026-11-30 10:15:26 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tyr0nsur on 2026-11-30T10:15:26Z.


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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7275343506 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3877#issuecomment-7275343506). Originally posted by [tyr0nsur](https://github.com/tyr0nsur) on 2026-11-30T10:15:26Z. --- 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)
tikD1337 commented 2026-11-30 13:57:58 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tikD1337 on 2026-11-30T13:57:58Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7280630646 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3877#issuecomment-7280630646). Originally posted by [tikD1337](https://github.com/tikD1337) on 2026-11-30T13:57:58Z. --- 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 commented 2026-11-30 16:59:35 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by tikD1337 on 2026-11-30T16:59:35Z.


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!

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7285548696 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3877#issuecomment-7285548696). Originally posted by [tikD1337](https://github.com/tikD1337) on 2026-11-30T16:59:35Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
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.

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