VSP-03: split large lazy title-memory sections #17

Manually merged
github merged 1 commit from github-bot/gh-17 into main 2026-12-01 23:40:59 +00:00 AGit
Owner

@⁠FeelsGoodMan2 on GitHub · 2026-11-30 10:00 UTC · original
FeelsGoodMan2:section-split → main · +181 −49 · 1 files · 1 commits · merged 2026-12-01 23:40 UTC

Summary

  • Claimed Task ID: VSP-03 (linked Task Claim issue: #4)
  • What this PR changes: Lazily committed allocations of title pages become several sections of at most 64 MB instead of one section of any size. Only crates/vesper-hle/src/modules/xmem.rs changes (with two unit tests).

Details:

  • VESPER_SECTION_MB sets the size (default 64; 0: one section per allocation, as before).
  • Sections committed upfront (32-bit heap, pools up to VESPER_INPLACE_HOT_MB) stay whole, because buffers in place need one stretch of one section.
  • Page numbers the title gets stay consecutive. If the host does not give all sections, those already made are closed and the call fails as before.
  • One log line when an allocation is cut. Here: 6,236 MB became 98 sections, 710 MB became 12.
  • Rebased onto main 7b7e556. Contiguous runs end where the section changes, so the coalescing needs no change.

Why

A CPU and context-switch trace (on the previous main, 24 s of switch data) has three gaps over 60 ms in the submit thread, almost all spent waiting for one system thread:

Gap Title thread waiting for it Waits
168 ms 157 ms 95
90 ms 80 ms 51
367 ms 342 ms 225

The title thread is in copy_page_mappings -> map_aliases -> map_alias -> MapViewOfFile3 / UnmapViewOfFile2. The system thread reads as large-page rebuilding, which walks all views of a section under its lock. I named its frames by comparing code with another kernel build whose symbols I have; the last ones match only at about 0.6-0.7 similarity.

AI Assistance Disclosure

  • No AI coding tools were used
  • AI coding tools were used (specify model/tool and what you manually verified): Claude Code (Claude Opus 5.5) wrote the code, the tests and this text, and computed the numbers. I played the runs below; I checked the visuals in the first A and the first B run (indoors and outdoors) and saw no problems.

Benchmark Comparison (Required for perf / GPU / memory changes)

Hardware: i5-13600KF, 32 GB RAM, RX 7800 XT 16 GB (driver 32.0.32029.2010), Windows 11 build 26300.

Profile: the settings of scripts\launch.cmd, but without hardware RT and with render scale 0.75 to 1440p; started by a script of my own, not through the launcher. Same executable, VESPER_SECTION_MB=0 (A, before) against 64 (B, after), each run from the same copied saves. Same route, driven by hand (not scripted). Four runs in the order B, A, A, B. All columns are the same stretch, 60 to 447 s after the first in-game frame. Frames with more than 1,000 draws. Numbers from VESPER_FRAME_CSV, GPU busy from the log.

Metric A run 1 A run 2 B run 1 B run 2
p50 FPS / ms 24.2 / 41.3 22.9 / 43.7 26.6 / 37.5 25.0 / 39.9
Avg FPS 21.2 19.5 25.0 23.5
p95 Frame Time (ms) 86.8 101.5 61.9 69.9
p99 ms 129.9 159.2 88.4 89.7
Max frame (ms) 350 382 299 137
Frames >100 ms (%) 2.70 5.21 0.42 0.56
Frames >100 ms per minute 34.3 60.8 6.3 7.9
Frames >200 ms per minute 1.8 5.0 0.3 0.0
Max >100 ms Streak (s) 0.93 0.83 0.37 0.32
Peak Private RAM (MB, whole run) 31,953 32,046 31,603 31,796
GPU busy, median / mean (%) 95 / 89.8 89 / 84.6 100 / 96.9 96 / 94.4
Draws per frame (median) 7,001 7,584 5,900 6,767
Free RAM in play, min / median (MB) 91 / 911 412 / 1,103 232 / 1,480 531 / 1,261

Weighted to the same mix of draws per frame (all four runs pooled), frames over 100 ms per 1,000: A 23.3 and 36.3, B 9.9 and 5.9.

What these numbers do not show:

  • A drew more per frame in both pairs although the route was the same; I do not know why. The weighting above accounts for it only roughly.
  • The two A runs differ by almost a factor of two, so one pair says little. Both B runs are better than both A runs.
  • I do not attribute the FPS difference to this PR.
  • Free RAM differed: about 6 s after start, 17.2 GB (A run 1), 8.5 GB (B run 1). Before launch, 19.9 GB (A run 2), 23.9 GB (B run 2). Among frames with 500-1000 MB free, B has fewer over 100 ms (8.3 and 11.0 against 32.0 and 54.6 per 1,000); with 1,000-2,000 MB likewise (2.9 and 4.1 against 23.9 and 55.6). Below 500 MB the first pair was equal (14.5 and 14.3); the second had almost no such frames.
  • Pipelines compiled during the run: 1,511 (A run 1), 2,117 (A run 2), 4,357 (B run 1), 2,549 (B run 2). B compiled more in both pairs.
  • Loading is left out.
  • Settled FPS was not measured. The second context-switch trace announced in #4 was recorded only on this branch, without a counterpart on the same main, so it is not used here.

Mandatory Verification Checklist

  • Diff obeys AGENTS.md, stays inside claimed VSP-XX files, and avoids the Maintainer Active Queue (ROADMAP.md)
  • cargo xtask policy and cargo test -p xtask --locked pass cleanly (315 files ok; 9 passed)
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings passes with 0 warnings
  • cargo xtask test-fast and cargo test --workspace --locked -- --test-threads=1 pass: test-fast passes; workspace (run with --no-fail-fast) 1259 passed, 5 failed, 47 ignored. The five are in vesper-shader, which this PR does not touch, and fail the same way on an untouched main here: first_half_values_render_on_hardware_and_warp, rectangles_are_drawn_whole, the_rectangle_stage_is_a_geometry_shader, normalized_buffer_formats_load_correctly_rounded_quotients, normalized_codes_truncate_back_to_themselves
  • Safety gates remain enabled (VESPER_WAIT_RESIDENT=textures, indirect clamping intact) and steady-state visuals are verified clean
  • Contains zero proprietary assets, keys, dumps, screenshots, or third-party studio/franchise names
  • Ready for 3 independent peer reviews (peer-review-gate) before maintainer review

The new test pages_of_a_large_pool_lie_in_many_sections_and_map_across_them fails with VESPER_SECTION_MB=0 (16,387 pages in one section) and passes by default.

🤖 Generated with Claude Code

**@⁠FeelsGoodMan2** on GitHub · 2026-11-30 10:00 UTC · [original](https://github.com/monte-alt/vesper/pull/17) `FeelsGoodMan2:section-split` → `main` · +181 −49 · 1 files · 1 commits · merged 2026-12-01 23:40 UTC ## Summary - **Claimed Task ID:** `VSP-03` (linked Task Claim issue: #4) - **What this PR changes:** Lazily committed allocations of title pages become several sections of at most 64 MB instead of one section of any size. Only `crates/vesper-hle/src/modules/xmem.rs` changes (with two unit tests). Details: - `VESPER_SECTION_MB` sets the size (default 64; `0`: one section per allocation, as before). - Sections committed upfront (32-bit heap, pools up to `VESPER_INPLACE_HOT_MB`) stay whole, because buffers in place need one stretch of one section. - Page numbers the title gets stay consecutive. If the host does not give all sections, those already made are closed and the call fails as before. - One log line when an allocation is cut. Here: 6,236 MB became 98 sections, 710 MB became 12. - Rebased onto `main` 7b7e556. Contiguous runs end where the section changes, so the coalescing needs no change. ## Why A CPU and context-switch trace (on the previous `main`, 24 s of switch data) has three gaps over 60 ms in the submit thread, almost all spent waiting for one system thread: | Gap | Title thread waiting for it | Waits | |---:|---:|---:| | 168 ms | 157 ms | 95 | | 90 ms | 80 ms | 51 | | 367 ms | 342 ms | 225 | The title thread is in `copy_page_mappings` -> `map_aliases` -> `map_alias` -> `MapViewOfFile3` / `UnmapViewOfFile2`. The system thread reads as large-page rebuilding, which walks all views of a section under its lock. I named its frames by comparing code with another kernel build whose symbols I have; the last ones match only at about 0.6-0.7 similarity. ## AI Assistance Disclosure - [ ] No AI coding tools were used - [x] AI coding tools were used (specify model/tool and what you manually verified): Claude Code (Claude Opus 5.5) wrote the code, the tests and this text, and computed the numbers. I played the runs below; I checked the visuals in the first A and the first B run (indoors and outdoors) and saw no problems. ## Benchmark Comparison (Required for perf / GPU / memory changes) Hardware: i5-13600KF, 32 GB RAM, RX 7800 XT 16 GB (driver 32.0.32029.2010), Windows 11 build 26300. Profile: the settings of `scripts\launch.cmd`, but **without hardware RT** and with render scale 0.75 to 1440p; started by a script of my own, not through the launcher. Same executable, `VESPER_SECTION_MB=0` (A, before) against `64` (B, after), each run from the same copied saves. Same route, driven by hand (not scripted). Four runs in the order B, A, A, B. All columns are the same stretch, 60 to 447 s after the first in-game frame. Frames with more than 1,000 draws. Numbers from `VESPER_FRAME_CSV`, GPU busy from the log. | Metric | A run 1 | A run 2 | B run 1 | B run 2 | |---|---:|---:|---:|---:| | p50 FPS / ms | 24.2 / 41.3 | 22.9 / 43.7 | 26.6 / 37.5 | 25.0 / 39.9 | | Avg FPS | 21.2 | 19.5 | 25.0 | 23.5 | | p95 Frame Time (ms) | 86.8 | 101.5 | 61.9 | 69.9 | | p99 ms | 129.9 | 159.2 | 88.4 | 89.7 | | Max frame (ms) | 350 | 382 | 299 | 137 | | Frames >100 ms (%) | 2.70 | 5.21 | 0.42 | 0.56 | | Frames >100 ms per minute | 34.3 | 60.8 | 6.3 | 7.9 | | Frames >200 ms per minute | 1.8 | 5.0 | 0.3 | 0.0 | | Max >100 ms Streak (s) | 0.93 | 0.83 | 0.37 | 0.32 | | Peak Private RAM (MB, whole run) | 31,953 | 32,046 | 31,603 | 31,796 | | GPU busy, median / mean (%) | 95 / 89.8 | 89 / 84.6 | 100 / 96.9 | 96 / 94.4 | | Draws per frame (median) | 7,001 | 7,584 | 5,900 | 6,767 | | Free RAM in play, min / median (MB) | 91 / 911 | 412 / 1,103 | 232 / 1,480 | 531 / 1,261 | Weighted to the same mix of draws per frame (all four runs pooled), frames over 100 ms per 1,000: A 23.3 and 36.3, B 9.9 and 5.9. **What these numbers do not show:** - A drew more per frame in both pairs although the route was the same; I do not know why. The weighting above accounts for it only roughly. - The two A runs differ by almost a factor of two, so one pair says little. Both B runs are better than both A runs. - I do not attribute the FPS difference to this PR. - Free RAM differed: about 6 s after start, 17.2 GB (A run 1), 8.5 GB (B run 1). Before launch, 19.9 GB (A run 2), 23.9 GB (B run 2). Among frames with 500-1000 MB free, B has fewer over 100 ms (8.3 and 11.0 against 32.0 and 54.6 per 1,000); with 1,000-2,000 MB likewise (2.9 and 4.1 against 23.9 and 55.6). Below 500 MB the first pair was equal (14.5 and 14.3); the second had almost no such frames. - Pipelines compiled during the run: 1,511 (A run 1), 2,117 (A run 2), 4,357 (B run 1), 2,549 (B run 2). B compiled more in both pairs. - Loading is left out. - Settled FPS was not measured. The second context-switch trace announced in #4 was recorded only on this branch, without a counterpart on the same `main`, so it is not used here. ## Mandatory Verification Checklist - [x] Diff obeys `AGENTS.md`, stays inside claimed `VSP-XX` files, and avoids the Maintainer Active Queue (`ROADMAP.md`) - [x] `cargo xtask policy` and `cargo test -p xtask --locked` pass cleanly (315 files ok; 9 passed) - [x] `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` passes with 0 warnings - [ ] `cargo xtask test-fast` and `cargo test --workspace --locked -- --test-threads=1` pass: `test-fast` passes; workspace (run with `--no-fail-fast`) 1259 passed, **5 failed**, 47 ignored. The five are in `vesper-shader`, which this PR does not touch, and fail the same way on an untouched `main` here: `first_half_values_render_on_hardware_and_warp`, `rectangles_are_drawn_whole`, `the_rectangle_stage_is_a_geometry_shader`, `normalized_buffer_formats_load_correctly_rounded_quotients`, `normalized_codes_truncate_back_to_themselves` - [x] Safety gates remain enabled (`VESPER_WAIT_RESIDENT=textures`, indirect clamping intact) and steady-state visuals are verified clean - [x] Contains zero proprietary assets, keys, dumps, screenshots, or third-party studio/franchise names - [x] Ready for **3 independent peer reviews** (`peer-review-gate`) before maintainer review The new test `pages_of_a_large_pool_lie_in_many_sections_and_map_across_them` fails with `VESPER_SECTION_MB=0` (16,387 pages in one section) and passes by default. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The host keeps the views of a section in one list under one lock, and a
system thread rebuilding large pages walks it for each shared page it
takes. Whoever maps or unmaps a view of that section waits. With a pool
of several GB in one section the title's thread waits 1 to 4 ms a page.

Lazily committed allocations become sections of at most
VESPER_SECTION_MB (64; 0: one section per allocation, as before).
Sections committed upfront stay whole.

Claim: #4

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

@⁠adriaespii on GitHub · 2026-11-30 20:33 UTC · original · approved these changes

Independent 6-point peer review (AGENTS.md Section 6):

  1. Claim & Scope: Verified against VSP-03 / claim #4. Diff touches only crates/vesper-hle/src/modules/xmem.rs (matches ROADMAP.md Primary Files) and avoids the Maintainer Active Queue.
  2. Safety & Visual Integrity: Upfront whole_committed sections (32-bit heaps and in-place hot pools) remain uncut so OpenExistingHeapFromFileMapping stays intact. Partial-allocation cleanup closes all previously created handles and restores SetLastError cleanly. No GPU safety barriers or clamping paths are touched.
  3. Benchmarks: Solid 4-run interleaved A/B (B, A, A, B) on identical hardware and route showing a clear drop in >100 ms spikes (34.3–60.8/min -> 6.3–7.9/min) and p99 (129.9–159.2 ms -> 88.4–89.7 ms), with caveats candidly documented.
  4. Build & Test Proof: Adds two focused unit tests, including pages_of_a_large_pool_lie_in_many_sections_and_map_across_them, verifying consecutive page numbering, section-boundary
    uns() splitting, and map_aliases coherency across a cut boundary.
  5. Clean-Room Compliance: Zero game assets, screenshots, keys, or banned third-party/franchise names.
  6. Code Correctness & xtask Integrity: Clean helper decomposition (section_pages_most, section_lengths, make_section, make_sections), all unsafe blocks carry // SAFETY: comments, and VESPER_SECTION_MB is read as a literal in xmem.rs.

(AI-assisted code audit using Antigravity/Gemini.)

**@⁠adriaespii** on GitHub · 2026-11-30 20:33 UTC · [original](https://github.com/monte-alt/vesper/pull/17#pullrequestreview-6120056267) · **approved these changes** Independent 6-point peer review (AGENTS.md Section 6): 1. **Claim & Scope:** Verified against VSP-03 / claim #4. Diff touches only crates/vesper-hle/src/modules/xmem.rs (matches ROADMAP.md Primary Files) and avoids the Maintainer Active Queue. 2. **Safety & Visual Integrity:** Upfront whole_committed sections (32-bit heaps and in-place hot pools) remain uncut so OpenExistingHeapFromFileMapping stays intact. Partial-allocation cleanup closes all previously created handles and restores SetLastError cleanly. No GPU safety barriers or clamping paths are touched. 3. **Benchmarks:** Solid 4-run interleaved A/B (B, A, A, B) on identical hardware and route showing a clear drop in >100 ms spikes (34.3–60.8/min -> 6.3–7.9/min) and p99 (129.9–159.2 ms -> 88.4–89.7 ms), with caveats candidly documented. 4. **Build & Test Proof:** Adds two focused unit tests, including pages_of_a_large_pool_lie_in_many_sections_and_map_across_them, verifying consecutive page numbering, section-boundary uns() splitting, and map_aliases coherency across a cut boundary. 5. **Clean-Room Compliance:** Zero game assets, screenshots, keys, or banned third-party/franchise names. 6. **Code Correctness & xtask Integrity:** Clean helper decomposition (section_pages_most, section_lengths, make_section, make_sections), all unsafe blocks carry // SAFETY: comments, and VESPER_SECTION_MB is read as a literal in xmem.rs. *(AI-assisted code audit using Antigravity/Gemini.)*
Author
Owner

@⁠monte-alt on GitHub · 2026-11-30 20:57 UTC · original

thank you for this. i ran the xmem tests and checked the second machine’s CSVs. frames over 100 ms went from 215 to 63, even with similar draw counts. can you repeat on current main with 64 first this time?

**@⁠monte-alt** on GitHub · 2026-11-30 20:57 UTC · [original](https://github.com/monte-alt/vesper/pull/17#issuecomment-7291718394) thank you for this. i ran the xmem tests and checked the second machine’s CSVs. frames over 100 ms went from 215 to 63, even with similar draw counts. can you repeat on current main with 64 first this time?
Author
Owner

@⁠FeelsGoodMan2 on GitHub · 2026-11-30 21:57 UTC · original

Repeated on main with 64 first: b262c73 (v0.9.0) plus this PR's commit, applied without conflicts. main has moved on since, by documentation only.

Setup as in the PR (i5-13600KF, 32 GB RAM, RX 7800 XT, inbox D3D12, 1440p at render scale 0.75, no hardware RT), same executable, same copied saves, driven by hand. One run each: B (VESPER_SECTION_MB=64), then A (0). The only other change of settings against the PR's runs is VESPER_SKIP_INTRO=1, in both. Stretch 60 to 447 s after the first in-game frame, frames with more than 1,000 draws.

Metric B, 64 (first) A, 0 (second)
Frames 7,252 4,875
p50 FPS / ms 22.7 / 44.1 19.6 / 51.0
Avg FPS 20.0 16.0
p95 ms 90.8 141.5
p99 ms 117.6 282.8
Max frame ms 1,800 598
Frames >100 ms 2.84 % (34.1 per minute) 9.19 % (88.3 per minute)
Frames >200 ms 3 116
Max >100 ms streak (s) 1.80 1.50
GPU busy, median / mean (%) 89 / 87.0 74 / 66.4
Peak private RAM (MB, whole run) 34,354 31,849
Draws per frame (median) 7,073 8,060
Free RAM in play, min / median (MB) 196 / 1,350 484 / 1,428
Pipelines compiled during the run 2,601 827

Weighted to the same mix of draws per frame, frames over 100 ms per 1,000: B 30.5, A 85.0. With all frames of the stretch, also those with few draws: 2.63 % and 7.05 %.

With 64 the log shows mb=6236 sections=98 and mb=710 sections=12; with 0 it does not.

Claude Code (Claude Opus 5.5) computed the numbers and wrote this text; I played the runs.

**@⁠FeelsGoodMan2** on GitHub · 2026-11-30 21:57 UTC · [original](https://github.com/monte-alt/vesper/pull/17#issuecomment-7293135613) Repeated on `main` with 64 first: `b262c73` (v0.9.0) plus this PR's commit, applied without conflicts. `main` has moved on since, by documentation only. Setup as in the PR (i5-13600KF, 32 GB RAM, RX 7800 XT, inbox D3D12, 1440p at render scale 0.75, no hardware RT), same executable, same copied saves, driven by hand. One run each: B (`VESPER_SECTION_MB=64`), then A (`0`). The only other change of settings against the PR's runs is `VESPER_SKIP_INTRO=1`, in both. Stretch 60 to 447 s after the first in-game frame, frames with more than 1,000 draws. | Metric | B, 64 (first) | A, 0 (second) | |---|---:|---:| | Frames | 7,252 | 4,875 | | p50 FPS / ms | 22.7 / 44.1 | 19.6 / 51.0 | | Avg FPS | 20.0 | 16.0 | | p95 ms | 90.8 | 141.5 | | p99 ms | 117.6 | 282.8 | | Max frame ms | 1,800 | 598 | | Frames >100 ms | 2.84 % (34.1 per minute) | 9.19 % (88.3 per minute) | | Frames >200 ms | 3 | 116 | | Max >100 ms streak (s) | 1.80 | 1.50 | | GPU busy, median / mean (%) | 89 / 87.0 | 74 / 66.4 | | Peak private RAM (MB, whole run) | 34,354 | 31,849 | | Draws per frame (median) | 7,073 | 8,060 | | Free RAM in play, min / median (MB) | 196 / 1,350 | 484 / 1,428 | | Pipelines compiled during the run | 2,601 | 827 | Weighted to the same mix of draws per frame, frames over 100 ms per 1,000: B 30.5, A 85.0. With all frames of the stretch, also those with few draws: 2.63 % and 7.05 %. With 64 the log shows `mb=6236 sections=98` and `mb=710 sections=12`; with 0 it does not. Claude Code (Claude Opus 5.5) computed the numbers and wrote this text; I played the runs.
github manually merged commit 78f54f756a into main 2026-12-01 23:40:59 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.