perf(victory): batch K32QueryWorkingSetEx queries in texture::mapped_bytes #439

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

@⁠mauroalvare on GitHub · 2026-11-26 18:47 UTC · original
mauroalvare:perf/victory-mapped-bytes-batch → main · +289 −38 · 1 files · 2 commits · closed without merging

Change

texture::mapped_bytes() is called on every placed texture view scanned by State::heap_textures() (thousands of slots per frame during streaming) and during resource::card_accounting().

Previously, in the default QueryWorkingSetEx path:

  • The fast endpoint check called committed(at, 1) and committed(end - 1, 1) separately — two K32QueryWorkingSetEx syscalls even for completely unmapped ("away") slots or single-page ranges.
  • Once either endpoint was mapped, the 64 KiB block loop called readable(lo, 1, true) per block — one K32QueryWorkingSetEx syscall per 64 KiB block (e.g. 65 syscalls for a 4 MiB texture, 257 syscalls for a 16 MiB texture, 2 syscalls even for a 64 KiB texture).

This change batches K32QueryWorkingSetEx queries in texture::mapped_bytes() while keeping identical block-probing semantics (including the host::read_into fallback for committed-but-untouched pages not yet in the working set, and keeping VICTORY_COMMITTED_QUERY=1 and VICTORY_MAPPED_BY_PAGE=1 intact):

  • Probes [first_page, last_page] (deduplicated to 1 entry when they are the same 4 KiB page) in a single 2-entry K32QueryWorkingSetEx call on a 32-byte stack buffer, avoiding any 4 KiB stack array initialization for unmapped ("away") or single-block (<= 64 KiB) textures.
  • Reuses first_ok for block 0 (start's 64 KiB block) instead of re-querying it.
  • Batches remaining 64 KiB blocks up to 256 blocks (16 MiB) per K32QueryWorkingSetEx syscall (cutting a 4 MiB or 16 MiB resident texture from 65 / 257 syscalls down to 2).

Verification

Base SHA: c3cc02932fc596ee9d937e5743f73007c538365a (LooperSalty/AnyXboxX:main).
Hardware: Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM, driver 32.0.16.2140), 32 GB RAM.

Synthetic streaming sweep benchmark (--release, 10 sweeps × 2,900 slots = 29,000 calls)

Command (identical test and --release profile on base vs fix):

cargo test --locked --release -p victory-gpu --lib mapped_bytes_tests -- --nocapture --test-threads=1
Category (10 sweeps) Base (c3cc029) Fix (median of 3 runs) Speedup
16MiB_full (100 slots) 100.88 ms 4.46 ms (4.41–5.11 ms) 22.6× faster (-95.6%)
4MiB_full (400 slots) 95.45 ms 8.20 ms (7.22–8.59 ms) 11.6× faster (-91.4%)
4MiB_half (400 slots) 331.50 ms 197.45 ms (187.45–200.79 ms) 1.68× faster (-40.4%)
4MiB_away (1,600 slots) 111.15 ms 53.27 ms (50.13–55.50 ms) 2.09× faster (-52.1%)
64KiB_full (400 slots) 2.70 ms 1.27 ms (1.25–1.29 ms) 2.13× faster (-53.0%)
Total (2,900 slots × 10 sweeps) 641.67 ms 265.29 ms (251.88–269.22 ms) 2.42× faster (-58.7%)

(All timings above are from the synthetic mapped_bytes_streaming_sweep_benchmark test; no game files or in-game FPS measurements were used.)

Test & policy checks

cargo test --locked -p victory-gpu --lib texture:: -- --nocapture --test-threads=1
# → test result: ok. 9 passed; 0 failed; 0 ignored; 0 measured; 256 filtered out; finished in 1.92s
#   (includes stage_pool_tests and zero_upload_tests on NVIDIA GeForce RTX 5070 Ti)

cargo test --locked -p victory-gpu --lib --features diagnostics texture:: -- --test-threads=1
# → test result: ok. 9 passed; 0 failed; 0 ignored; 0 measured; 268 filtered out; finished in 1.96s

cargo test --locked -p victory-loader --test load_probe
# → test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.24s

cargo clippy --locked -p victory-gpu --tests
# → Finished `dev` profile [unoptimized + debuginfo] (0 warnings in texture.rs)

cargo xtask policy
# → asset policy: 215 files ok

Oracle and test data

  • All test data is synthetic virtual memory allocated via VirtualAlloc (MEM_RESERVE / MEM_COMMIT / MEM_DECOMMIT / MEM_RELEASE) inside texture::mapped_bytes_tests.
  • mapped_bytes_matches_block_oracle_across_layouts verifies exact byte-for-byte agreement against a 64 KiB block oracle across zero-length, unmapped, committed-but-untouched (read_into fallback), sub-page, single-block, unaligned start/end, middle-hole, >16 MiB (>256 blocks, multi-batch), unmapped-start/mapped-tail, and last-page-only single-block edge cases.

Checklist

  • The PR covers a single reviewable behaviour.
  • Synthetic correctness and benchmark tests cover the change and verify identical results with measured speedup.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: no README changes needed.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none (purely synthetic tests and public Win32 K32QueryWorkingSetEx documentation).
  • Code taken from another project: none.

This change was investigated, implemented, and verified with AI assistance.

**@⁠mauroalvare** on GitHub · 2026-11-26 18:47 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/439) `mauroalvare:perf/victory-mapped-bytes-batch` → `main` · +289 −38 · 1 files · 2 commits · closed without merging ## Change `texture::mapped_bytes()` is called on every placed texture view scanned by `State::heap_textures()` (thousands of slots per frame during streaming) and during `resource::card_accounting()`. Previously, in the default `QueryWorkingSetEx` path: - The fast endpoint check called `committed(at, 1)` and `committed(end - 1, 1)` separately — **two** `K32QueryWorkingSetEx` syscalls even for completely unmapped ("away") slots or single-page ranges. - Once either endpoint was mapped, the 64 KiB block loop called `readable(lo, 1, true)` per block — **one** `K32QueryWorkingSetEx` syscall per 64 KiB block (e.g. 65 syscalls for a 4 MiB texture, 257 syscalls for a 16 MiB texture, 2 syscalls even for a 64 KiB texture). This change batches `K32QueryWorkingSetEx` queries in `texture::mapped_bytes()` while keeping identical block-probing semantics (including the `host::read_into` fallback for committed-but-untouched pages not yet in the working set, and keeping `VICTORY_COMMITTED_QUERY=1` and `VICTORY_MAPPED_BY_PAGE=1` intact): - Probes `[first_page, last_page]` (deduplicated to 1 entry when they are the same 4 KiB page) in a single 2-entry `K32QueryWorkingSetEx` call on a 32-byte stack buffer, avoiding any 4 KiB stack array initialization for unmapped ("away") or single-block (`<= 64 KiB`) textures. - Reuses `first_ok` for block 0 (`start`'s 64 KiB block) instead of re-querying it. - Batches remaining 64 KiB blocks up to 256 blocks (16 MiB) per `K32QueryWorkingSetEx` syscall (cutting a 4 MiB or 16 MiB resident texture from 65 / 257 syscalls down to 2). ## Verification Base SHA: `c3cc02932fc596ee9d937e5743f73007c538365a` (`LooperSalty/AnyXboxX:main`). Hardware: Windows x64, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (15995 MiB VRAM, driver `32.0.16.2140`), 32 GB RAM. ### Synthetic streaming sweep benchmark (`--release`, 10 sweeps × 2,900 slots = 29,000 calls) Command (identical test and `--release` profile on base vs fix): ```powershell cargo test --locked --release -p victory-gpu --lib mapped_bytes_tests -- --nocapture --test-threads=1 ``` | Category (10 sweeps) | Base (`c3cc029`) | Fix (median of 3 runs) | Speedup | | --- | ---: | ---: | ---: | | `16MiB_full` (100 slots) | 100.88 ms | 4.46 ms (4.41–5.11 ms) | **22.6× faster** (-95.6%) | | `4MiB_full` (400 slots) | 95.45 ms | 8.20 ms (7.22–8.59 ms) | **11.6× faster** (-91.4%) | | `4MiB_half` (400 slots) | 331.50 ms | 197.45 ms (187.45–200.79 ms) | **1.68× faster** (-40.4%) | | `4MiB_away` (1,600 slots) | 111.15 ms | 53.27 ms (50.13–55.50 ms) | **2.09× faster** (-52.1%) | | `64KiB_full` (400 slots) | 2.70 ms | 1.27 ms (1.25–1.29 ms) | **2.13× faster** (-53.0%) | | **Total (2,900 slots × 10 sweeps)** | **641.67 ms** | **265.29 ms** (251.88–269.22 ms) | **2.42× faster** (-58.7%) | *(All timings above are from the synthetic `mapped_bytes_streaming_sweep_benchmark` test; no game files or in-game FPS measurements were used.)* ### Test & policy checks ```powershell cargo test --locked -p victory-gpu --lib texture:: -- --nocapture --test-threads=1 # → test result: ok. 9 passed; 0 failed; 0 ignored; 0 measured; 256 filtered out; finished in 1.92s # (includes stage_pool_tests and zero_upload_tests on NVIDIA GeForce RTX 5070 Ti) cargo test --locked -p victory-gpu --lib --features diagnostics texture:: -- --test-threads=1 # → test result: ok. 9 passed; 0 failed; 0 ignored; 0 measured; 268 filtered out; finished in 1.96s cargo test --locked -p victory-loader --test load_probe # → test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 2.24s cargo clippy --locked -p victory-gpu --tests # → Finished `dev` profile [unoptimized + debuginfo] (0 warnings in texture.rs) cargo xtask policy # → asset policy: 215 files ok ``` ## Oracle and test data - All test data is synthetic virtual memory allocated via `VirtualAlloc` (`MEM_RESERVE` / `MEM_COMMIT` / `MEM_DECOMMIT` / `MEM_RELEASE`) inside `texture::mapped_bytes_tests`. - `mapped_bytes_matches_block_oracle_across_layouts` verifies exact byte-for-byte agreement against a 64 KiB block oracle across zero-length, unmapped, committed-but-untouched (`read_into` fallback), sub-page, single-block, unaligned start/end, middle-hole, >16 MiB (>256 blocks, multi-batch), unmapped-start/mapped-tail, and last-page-only single-block edge cases. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] Synthetic correctness and benchmark tests cover the change and verify identical results with measured speedup. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: no README changes needed. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none (purely synthetic tests and public Win32 `K32QueryWorkingSetEx` documentation). - [x] Code taken from another project: none. *This change was investigated, implemented, and verified with AI assistance.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:56:36 +00:00
github-bot force-pushed github-bot/gh-439 from 918dbad29b to 5a253f8a04 2026-11-26 19:50:57 +00:00 Compare
github-bot force-pushed github-bot/gh-439 from 5a253f8a04 to b945c2f7f0 2026-11-27 00:35:51 +00:00 Compare
github-bot closed this pull request 2026-11-27 00:35:51 +00:00
Author
Owner

@⁠LooperSalty on GitHub · 2026-11-26 23:08 UTC · original

Closing after #454 moved third_party/victory to the Vice-Tay base (TaynanGT/Vice-Tay a252348).

On the new base the default path counts mapped bytes through inplace::shown_bytes (VICTORY_MAPPED_BY_VIEWS), so the per-block K32QueryWorkingSetEx loop is no longer on the hot path, and no gain was measured.

Thanks for the work. If you measure a gain on the new base, a new PR against main is welcome.

🤖 Closed by Claude Code on behalf of the maintainer

**@⁠LooperSalty** on GitHub · 2026-11-26 23:08 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/439#issuecomment-7205294808) Closing after #454 moved `third_party/victory` to the Vice-Tay base (TaynanGT/Vice-Tay a252348). On the new base the default path counts mapped bytes through `inplace::shown_bytes` (`VICTORY_MAPPED_BY_VIEWS`), so the per-block `K32QueryWorkingSetEx` loop is no longer on the hot path, and no gain was measured. Thanks for the work. If you measure a gain on the new base, a new PR against `main` is welcome. _🤖 Closed by [Claude Code](https://claude.com/claude-code) on behalf of the maintainer_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.