perf(gpu): avoid repeated placeholder queries within uncommitted regions #580

Open
github-bot wants to merge 2 commits from github-bot/gh-580 into main AGit
Owner

@⁠tommiehansen on GitHub · 2026-12-05 11:19 UTC · original
tommiehansen:perf/guard-placeholder-region-cache → main · +105 −2 · 1 files · 2 commits · open

Why

Placeholder classification repeats native queries for each block of an already bounded uncommitted run.

What changes

Cache classification only within intersection of VirtualQuery run and returned allocation region; failed/inconsistent answers do not extend beyond one block.

Benchmark results

512 blocks: 512→1 native queries, 159.45→1.05 µs, paired −99.34% (8 blocks). Independent fragmented 48-window test: 222→108 calls, exact classifications/absent/held sets.

Why this should be merged / current decision

Avoids redundant syscalls without changing protection decisions; ready for review.

Validation

Native CI passed split and private-boundary tests in debug/release. Independent verification: same five inherited suite failures as main, no new failures.

Compatibility

No new switch. Distinct from #513/#334/#381; no frame-time inference.

Archived detailed evidence and review history.

**@⁠tommiehansen** on GitHub · 2026-12-05 11:19 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/580) `tommiehansen:perf/guard-placeholder-region-cache` → `main` · +105 −2 · 1 files · 2 commits · open ## Why Placeholder classification repeats native queries for each block of an already bounded uncommitted run. ## What changes Cache classification only within intersection of VirtualQuery run and returned allocation region; failed/inconsistent answers do not extend beyond one block. ## Benchmark results 512 blocks: 512→1 native queries, 159.45→1.05 µs, paired −99.34% (8 blocks). Independent fragmented 48-window test: 222→108 calls, exact classifications/absent/held sets. ## Why this should be merged / current decision Avoids redundant syscalls without changing protection decisions; ready for review. ## Validation [Native CI](https://github.com/tommiehansen/VIctory-xmem/actions/runs/47514526067/job/145656986532) passed split and private-boundary tests in debug/release. [Independent verification](https://git.gtahub.st/github/lobomfz--VIctory-xmem/pulls/580): same five inherited suite failures as main, no new failures. ## Compatibility No new switch. Distinct from #513/#334/#381; no frame-time inference. [Archived detailed evidence and review history](https://github.com/tommiehansen/VIctory-xmem/blob/04dd44857abe222961157663b89a4dfed4c7277c/archive/pr-descriptions-20261206.md).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 11:23:56 +00:00
Author
Owner

@⁠Kal0s-design on GitHub · 2026-12-05 11:58 UTC · original

Native Windows check of e35ac10 (MSVC build, Windows 11, no Wine), compared against main at 8bf4878.

The watch tests pass (39 passed, the benchmark ignored). The full victory-gpu lib suite, skipping descriptor::tests::views_die_with_their_resource, gives the same five failures as main on this machine and nothing new. Those are the two indirect host_list tests, the two pipeline::host library loads and the_rest_of_the_one_asking_has_a_number_of_its_own. The last one is the known flaky watch test and passes when rerun on its own.

The ignored benchmark passes natively. Query count goes from 512 to 1 with identical classification, and in a release build the median walk over the 512 block placeholder is about 200x faster (three runs, very stable). That is a microbenchmark of the classification loop only, not a frame time number.

I also wanted to see the real protect_mapped path on a messier layout, so I wrote a throwaway local test (not pushed). It carves one 24 block placeholder into split placeholder pieces of 4, 3, 1, 3 and 3 blocks, a released block that leaves a MEM_FREE hole, a committed MEM_REPLACE_PLACEHOLDER private block, a 3 block section view mapped with MEM_REPLACE_PLACEHOLDER, a reserve-only MEM_REPLACE_PLACEHOLDER allocation with one block committed in the middle, and a reserve-only block with only its first 4 KiB committed. It then calls protect_mapped from every start offset, plus short windows, and compares held against a fresh per-block NtQueryVirtualMemory answer for every absent block. All 48 runs matched, and the absent and held sets of the full-range walk came out identical to the same test on main.

Some native details that might help. A VirtualQuery reserved run never crossed an allocation here, so the allocation-region bound mostly coincides with the uncommitted run. The one place they differ is the reserve-only allocation with a committed block inside, where region_size runs to the end of the allocation and the VirtualQuery bound is the one that stops the reuse, as intended. The free hole in my layout was a single block, so it got its own query as on main. From reading the code a longer free run should also stay at one query per block, and flooring end / BLOCK means a partial trailing block always gets its own query, which seems right. Since the cached value lives only inside one protect_mapped call, there is nothing to invalidate on free, unmap or remap. In this fragmented layout the saving was 222 queries down to 108 across all start offsets, so the big win depends on long unsplit placeholders like the benchmark's.

I see no correctness problem. git merge-tree reports no textual conflict with #581, #513, #312 or #559.

AI-assisted: yes

**@⁠Kal0s-design** on GitHub · 2026-12-05 11:58 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/580#issuecomment-7437584839) Native Windows check of e35ac10 (MSVC build, Windows 11, no Wine), compared against main at 8bf4878. The watch tests pass (39 passed, the benchmark ignored). The full victory-gpu lib suite, skipping descriptor::tests::views_die_with_their_resource, gives the same five failures as main on this machine and nothing new. Those are the two indirect host_list tests, the two pipeline::host library loads and the_rest_of_the_one_asking_has_a_number_of_its_own. The last one is the known flaky watch test and passes when rerun on its own. The ignored benchmark passes natively. Query count goes from 512 to 1 with identical classification, and in a release build the median walk over the 512 block placeholder is about 200x faster (three runs, very stable). That is a microbenchmark of the classification loop only, not a frame time number. I also wanted to see the real protect_mapped path on a messier layout, so I wrote a throwaway local test (not pushed). It carves one 24 block placeholder into split placeholder pieces of 4, 3, 1, 3 and 3 blocks, a released block that leaves a MEM_FREE hole, a committed MEM_REPLACE_PLACEHOLDER private block, a 3 block section view mapped with MEM_REPLACE_PLACEHOLDER, a reserve-only MEM_REPLACE_PLACEHOLDER allocation with one block committed in the middle, and a reserve-only block with only its first 4 KiB committed. It then calls protect_mapped from every start offset, plus short windows, and compares held against a fresh per-block NtQueryVirtualMemory answer for every absent block. All 48 runs matched, and the absent and held sets of the full-range walk came out identical to the same test on main. Some native details that might help. A VirtualQuery reserved run never crossed an allocation here, so the allocation-region bound mostly coincides with the uncommitted run. The one place they differ is the reserve-only allocation with a committed block inside, where region_size runs to the end of the allocation and the VirtualQuery bound is the one that stops the reuse, as intended. The free hole in my layout was a single block, so it got its own query as on main. From reading the code a longer free run should also stay at one query per block, and flooring end / BLOCK means a partial trailing block always gets its own query, which seems right. Since the cached value lives only inside one protect_mapped call, there is nothing to invalidate on free, unmap or remap. In this fragmented layout the saving was 222 queries down to 108 across all start offsets, so the big win depends on long unsplit placeholders like the benchmark's. I see no correctness problem. git merge-tree reports no textual conflict with #581, #513, #312 or #559. AI-assisted: yes
Author
Owner

@⁠tommiehansen on GitHub · 2026-12-05 12:28 UTC · original

Thanks for the additional fragmented-layout verification. The 48-window parity and 222→108 query result are now documented separately from the contiguous microbenchmark. No code change was indicated by the review.

**@⁠tommiehansen** on GitHub · 2026-12-05 12:28 UTC · [original](https://github.com/lobomfz/VIctory-xmem/pull/580#issuecomment-7437975123) Thanks for the additional fragmented-layout verification. The 48-window parity and 222→108 query result are now documented separately from the contiguous microbenchmark. No code change was indicated by the review.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/580/head:github-bot/gh-580'
git switch 'github-bot/gh-580'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-580'
git switch 'github-bot/gh-580'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-580'
git switch 'github-bot/gh-580'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-580'
git switch 'main'
git merge --squash 'github-bot/gh-580'
git switch 'main'
git merge --ff-only 'github-bot/gh-580'
git switch 'main'
git merge 'github-bot/gh-580'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.