Perf/indexed copyback ranges #1869

Open
github-bot wants to merge 3 commits from github-bot/gh-1869 into main AGit
Owner

@⁠VlREX on GitHub · 2026-11-24 23:53 UTC · original
VlREX:perf/indexed-copyback-ranges → main · +204 −2 · 2 files · 3 commits · open

Replace linear precise UAV range scans with a sorted prefix-maximum interval index and binary search. Synthetic lookup comparisons reduced from 6,292,480 to 45,058, excluding index construction. Independently verified with 102,464 JavaScript model queries and 131,072 native C queries, zero mismatches. Four Rust tests included. Native Rust and GPU benchmarks pending. Complementary to #1865. AI-assisted (ChatGPT).

**@⁠VlREX** on GitHub · 2026-11-24 23:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/1869) `VlREX:perf/indexed-copyback-ranges` → `main` · +204 −2 · 2 files · 3 commits · open Replace linear precise UAV range scans with a sorted prefix-maximum interval index and binary search. Synthetic lookup comparisons reduced from 6,292,480 to 45,058, excluding index construction. Independently verified with 102,464 JavaScript model queries and 131,072 native C queries, zero mismatches. Four Rust tests included. Native Rust and GPU benchmarks pending. Complementary to #1865. AI-assisted (ChatGPT).
Keep small and lightly queried lists linear; defer sorting until 32 full-scan equivalents. Release the declaration guard before copying pages. Add adaptive transition and reference-equivalence tests. Threshold is a heuristic motivated by the synthetic Windows benchmark, not an in-game measurement.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:47:08 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 00:10 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at b118e79: cargo test -p victory-gpu --locked gives 80 passed, 2 failed, 1 ignored. The two failures are the NVIDIA heap-cap ones main also has (descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, #1744), so there is nothing new on this hardware. Not run: a title.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 00:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1869#issuecomment-7148235094) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `b118e79`: `cargo test -p victory-gpu --locked` gives 80 passed, 2 failed, 1 ignored. The two failures are the NVIDIA heap-cap ones `main` also has (`descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`, #1744), so there is nothing new on this hardware. Not run: a title. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 07:26 UTC · original · edited 2026-11-25 22:19 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflict in crates/victory-gpu/src/memory.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: a number from a real frame showing the linear scan costs something (range counts or before/after copy-back ms), a descriptive PR title, and rustfmt on precise_ranges.rs.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 07:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/1869#issuecomment-7155864576) · edited 2026-11-25 22:19 UTC <!-- victory-triage v1 head=163c39fffb76a0c14db047a12e972d9bdb26ce7b verdict=needs-rebase at=2026-11-25T22:23:30Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main` (conflict in `crates/victory-gpu/src/memory.rs`). It will be reviewed again once it is rebased. From the earlier needs-work note, still open: a number from a real frame showing the linear scan costs something (range counts or before/after copy-back ms), a descriptive PR title, and rustfmt on `precise_ranges.rs`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:59 UTC · original

Reviewed and verified 163c39ff on Windows 11 against main (13f91ca).

Code review

  • AdaptiveRanges cleanly addresses the upfront allocation/sorting overhead on small or early-exit sets: it scans linearly with zero allocation until n >= 8 and comparisons >= n.saturating_mul(32), only building the sorted prefix-max index when the range set actually gets hot. Dropping precise and declared right after the scan also avoids holding the byte_for_byte lock longer than needed.
  • Checked PreciseRanges::overlaps against the prior linear predicate a < to && from < a + len: saturating_add avoids end overflow, from >= to returns false, and partition_point(|&(start, _)| start < to) + prefix max_end > from matches on nested ranges, duplicate starts, zero-length ranges strictly inside a page vs. on boundaries, and saturating ends.

Verification (Windows 11, RTX 5090 + WARP)

  • VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1: 205 passed, 0 failed, 1 ignored (all 7 precise_ranges::tests pass).
  • RTX 5090: precise_ranges::tests 7/7, shadow::tests --test-threads=1 8/8, memory::tests --test-threads=1 4/5 (only the known 13f91ca RTX 5090 1M view-heap failure lists_share_a_table_and_copies_keep_their_views).
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings (default and --features diagnostics): 0 warnings; cargo xtask policy: 185 files ok.
  • Clean git merge-tree against 13f91ca as well as #2172, #2434, #2096, and #562.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/1869#issuecomment-7173037893) Reviewed and verified `163c39ff` on Windows 11 against `main` (`13f91ca`). ### Code review - `AdaptiveRanges` cleanly addresses the upfront allocation/sorting overhead on small or early-exit sets: it scans linearly with zero allocation until `n >= 8` and `comparisons >= n.saturating_mul(32)`, only building the sorted prefix-max index when the range set actually gets hot. Dropping `precise` and `declared` right after the scan also avoids holding the `byte_for_byte` lock longer than needed. - Checked `PreciseRanges::overlaps` against the prior linear predicate `a < to && from < a + len`: `saturating_add` avoids end overflow, `from >= to` returns `false`, and `partition_point(|&(start, _)| start < to)` + prefix `max_end > from` matches on nested ranges, duplicate starts, zero-length ranges strictly inside a page vs. on boundaries, and saturating ends. ### Verification (Windows 11, RTX 5090 + WARP) - `VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1`: **205 passed, 0 failed, 1 ignored** (all 7 `precise_ranges::tests` pass). - RTX 5090: `precise_ranges::tests` **7/7**, `shadow::tests --test-threads=1` **8/8**, `memory::tests --test-threads=1` **4/5** (only the known `13f91ca` RTX 5090 1M view-heap failure `lists_share_a_table_and_copies_keep_their_views`). - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings` (default and `--features diagnostics`): **0 warnings**; `cargo xtask policy`: **185 files ok**. - Clean `git merge-tree` against `13f91ca` as well as `#2172`, `#2434`, `#2096`, and `#562`.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 00:32 UTC · original · reviewed

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Indexed copyback ranges (docs+gpu): perf work on the copyback path, pairs with #1816's delivered-bytes accounting.

**@⁠catminou4** on GitHub · 2026-11-25 00:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1869#pullrequestreview-6049696616) · **reviewed** Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Indexed copyback ranges (docs+gpu): perf work on the copyback path, pairs with #1816's delivered-bytes accounting.
Author
Owner

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

In-game numbers for the linear search this PR replaces, since the description says native benchmarks are pending.
RX 6800 XT, Linux (Proton, vkd3d-proton), diag build with frame pointers of main 219878a plus our Linux
commits, a save in the prison, perf (cycles:u, call graphs) over 30 s in the world.

The search shows up as memory::bind::closure$2 (the after-run closure that copies back marked pages): 13.6 % and
12.9 % of the submitting thread's samples
in two runs. By source line, 95-97 % of that closure's own samples are the
precise.iter().any(...) line; scanning the bitmap itself is negligible. The list is long because draw.rs pushes a
root UAV's range for every draw or dispatch that binds it, so a list holds many copies of the same few ranges, and
every marked page is compared with all of them.

I tested the same idea in a smaller form on our branch: sort the ranges and merge overlapping or touching ones in
place (the bytes they cover stay the same, so a list that runs again searches the merged list), then a binary search
per page (partition_point; with disjoint sorted ranges only the last one starting before the page's end can overlap
it), with a test against the linear search over random, duplicated, touching and empty ranges. With it the closure
falls to 0.2 % of the thread. Frame times did not move measurably (it is one thread among several; 2 runs
each), so the gain is CPU time on the submitting thread rather than frame rate here.

Either version removes it; no need to change yours for this. Happy to share ours if a smaller diff helps.

AI-assisted (Claude Code). No game data attached.

**@⁠crashbashash** on GitHub · 2026-11-26 10:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1869#issuecomment-7188997953) In-game numbers for the linear search this PR replaces, since the description says native benchmarks are pending. RX 6800 XT, Linux (Proton, vkd3d-proton), `diag` build with frame pointers of `main` `219878a` plus our Linux commits, a save in the prison, perf (`cycles:u`, call graphs) over 30 s in the world. The search shows up as `memory::bind::closure$2` (the after-run closure that copies back marked pages): **13.6 % and 12.9 % of the submitting thread's samples** in two runs. By source line, 95-97 % of that closure's own samples are the `precise.iter().any(...)` line; scanning the bitmap itself is negligible. The list is long because `draw.rs` pushes a root UAV's range for every draw or dispatch that binds it, so a list holds many copies of the same few ranges, and every marked page is compared with all of them. I tested the same idea in a smaller form on our branch: sort the ranges and merge overlapping or touching ones in place (the bytes they cover stay the same, so a list that runs again searches the merged list), then a binary search per page (`partition_point`; with disjoint sorted ranges only the last one starting before the page's end can overlap it), with a test against the linear search over random, duplicated, touching and empty ranges. With it the closure falls to **0.2 %** of the thread. Frame times did not move measurably (it is one thread among several; 2 runs each), so the gain is CPU time on the submitting thread rather than frame rate here. Either version removes it; no need to change yours for this. Happy to share ours if a smaller diff helps. AI-assisted (Claude Code). No game data attached.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/memory.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/1869/head:github-bot/gh-1869'
git switch 'github-bot/gh-1869'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1869'
git switch 'github-bot/gh-1869'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1869'
git switch 'github-bot/gh-1869'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1869'
git switch 'main'
git merge --squash 'github-bot/gh-1869'
git switch 'main'
git merge --ff-only 'github-bot/gh-1869'
git switch 'main'
git merge 'github-bot/gh-1869'
git push origin 'main'
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/Marvisak--VIctory!1869
No description provided.