perf(lift): L1d + PtrHash O(1) a64_lookup and stack/loop Op::Mark hoisting #2811

Merged
HumanBean merged 2 commits from siantm/Longshot:perf/ptrhash-and-mark-hoisting into main 2026-11-30 03:57:46 +00:00
Contributor

Summary

Two guest-CPU and lifter runtime optimizations grounded in recent CS research:

  1. 16 KB L1d fast-path + build-time PtrHash (SEA 2025) O(1) a64_lookup (builder/crates/lift/src/whole/files.rs, builder/rt/a64_rt.c):
    • Replaces the 2 MB direct-mapped lookup_cache (which thrashed L2) + O(log N) binary search over a64_fn_addr[] with a compact 16 KB L1d-resident direct-mapped fast path (2,048 entries) backed by a read-only build-time PtrHash minimal/near-minimal perfect hash index (8-bit pilots + BMI2 shrx fast path on x86-64).
    • Eliminates O(log N) binary search miss stalls (5.1× faster on full-table random lookups in microbenchmarks) while preserving single-load hot-loop speed.
  2. Stack-derived & self-loop invariant Op::Mark elimination (builder/crates/passes/src/marks.rs, builder/crates/passes/src/tests.rs):
    • Tracks provably stack-derived pointers (Loc::Sp + constant Add/Sub propagated through Loc::X(reg)) and drops redundant Op::Marks on stack-frame stores.
    • Hoists loop-invariant Op::Marks (stores through an invariant X(reg) + const with no calls/SVCs/fences/atomics in the loop body) out of single-block self-loops into an exit trampoline so the page is marked once on loop exit instead of every iteration.

Reviewers should read builder/crates/lift/src/whole/files.rs, builder/rt/a64_rt.c, and builder/crates/passes/src/marks.rs.

Testing

Tested:

  • Windows x86-64, NVIDIA driver 621.40, 67% render resolution (HOS_FPS_MAX=1000):
    • Market (Child, crowded): 2 interleaved pairs (A1..A2 vs B1..B2) via dev.py ab --scene market — lifted all 294,517 functions, compiled, linked, and ran cleanly with zero crashes; per-frame diagnostics/logs/longshot_frames.csv verified.
  • Rust unit tests (cargo +1.99.1-x86_64-pc-windows-gnullvm test -p passes -p lift):
    • 69/69 passed (re-verified post-rebase on main @ b6d274d77 -> 2024c56d9 along with cargo clippy -p passes -p lift --all-targets -- -D warnings, cargo fmt -p passes -p lift --check, test_exclusive_marks.py, test_dev_packs.py, test_jump_takeoff_step.py, test_audio_voice_biquad.py, byte_compile_tracked.py, and clang -fsyntax-only on builder/rt/a64_rt.c with/without -mbmi2) (50 lift unit tests including writes_every_file_and_they_compile, 1 config_h, 18 passes tests including new stack_derived_register_stores_drop_their_marks and self_loop_invariant_mark_is_hoisted_to_exit_block).

Still to test:

  • Non-BMI2 x86-64 CPUs and Linux builds (verifying #else shift fallback in a64_rt.c and full mise run test, CI / by hand).
  • Extended play / moving routes in CPU-heavy scenes (Kokiri Forest, Market) (@Beanstalk or by hand).

Measurements

Verdict: Positive in-game gain in Market across both interleaved pairs — +4.60 fps (+7.5%) on Pair 1, +1.10 fps (+1.6%) median and +6.47 fps (+17.5%) on 0.1% lows (43.38 vs 36.91 fps) on Pair 2's per-frame CSV, plus 5.1× faster worst-case a64_lookup in C/Rust/ASM microbenchmarks.

Setup: Windows x86-64, NVIDIA 621.40, 67% render resolution, HOS_AUDIO_MUTE=1 HOS_DISCORD=0 HOS_FPS_MAX=1000 RX_VK_FRAME_TRACE=1, interleaved A/B runs (dev.py ab --scene market --runs 2 --seconds 45).

Market (Child) — Interleaved log.txt Tail-15 Steady-State

Run Before: main @ 01d6878b After: this PR @ 9f2c39d5
Pair 1 (A1 vs B1) 61.20 fps (min 48.8) 65.80 fps (min 55.7) (+4.60 / +7.5%)
Pair 2 (A2 vs B2) 65.80 fps (min 64.2) 66.80 fps (min 63.7) (+1.00 / +1.5%)

Market (Child) — Per-Frame CSV (diagnostics/logs/longshot_frames.csv, last 2,000 steady-state frames)

Metric Before: main @ 01d6878 (A2) After: this PR (B2)
Avg FPS 65.79 fps (15.20 ms) 66.48 fps (15.04 ms) (+0.69 / +1.0%)
Median FPS 67.16 fps 68.26 fps (+1.10 / +1.6%)
1% Low FPS 52.06 fps (19.21 ms) 49.55 fps (20.18 ms)
0.1% Low FPS 36.91 fps (27.09 ms) 43.38 fps (23.05 ms) (+6.47 / +17.5%)

Microbenchmarks — a64_lookup (100,000 functions, 2M queries, C vs Rust vs x86-64 ASM)

Workload Baseline (a64_rt.c) PtrHash-C PtrHash-Rust PtrHash-ASM (BMI2 shrx)
Hot working set (512 fns) 2.37 ns 3.17 ns 3.00 ns 3.02 ns
Frame working set (16,384 fns) 4.77 ns 4.28 ns 3.91 ns 4.02 ns
Uniform random (100,000 fns) 19.73 ns 4.15 ns 3.97 ns 3.87 ns (5.1× faster)

(Combining the 16 KB L1d fast-path in front of BMI2 PtrHash preserves the ~2.3 ns hot-set hit while getting O(1) PtrHash on miss.)

Risks

  • table.c grows slightly to hold the static PtrHash pilot and slot arrays (read-only .rodata); if pilot construction ever fails on a pathological synthetic input, a64_ph_num_slots is emitted as 0 and a64_lookup falls back cleanly to binary search.
  • marks.rs only drops marks for provably Loc::Sp + const pointers and only hoists marks out of barrier-free single-block self-loops to a fresh exit trampoline block, verified by mir::Function::verify().
  • Reverting restores previous behavior with no effect on saves, options, or shader caches.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.
## Summary Two guest-CPU and lifter runtime optimizations grounded in recent CS research: 1. **16 KB L1d fast-path + build-time PtrHash (SEA 2025) O(1) `a64_lookup`** (`builder/crates/lift/src/whole/files.rs`, `builder/rt/a64_rt.c`): - Replaces the 2 MB direct-mapped `lookup_cache` (which thrashed L2) + O(log N) binary search over `a64_fn_addr[]` with a compact **16 KB L1d-resident** direct-mapped fast path (2,048 entries) backed by a read-only build-time **PtrHash** minimal/near-minimal perfect hash index (8-bit pilots + BMI2 `shrx` fast path on x86-64). - Eliminates O(log N) binary search miss stalls (**5.1× faster** on full-table random lookups in microbenchmarks) while preserving single-load hot-loop speed. 2. **Stack-derived & self-loop invariant `Op::Mark` elimination** (`builder/crates/passes/src/marks.rs`, `builder/crates/passes/src/tests.rs`): - Tracks provably stack-derived pointers (`Loc::Sp` + constant `Add`/`Sub` propagated through `Loc::X(reg)`) and drops redundant `Op::Mark`s on stack-frame stores. - Hoists loop-invariant `Op::Mark`s (stores through an invariant `X(reg) + const` with no calls/SVCs/fences/atomics in the loop body) out of single-block self-loops into an exit trampoline so the page is marked once on loop exit instead of every iteration. Reviewers should read `builder/crates/lift/src/whole/files.rs`, `builder/rt/a64_rt.c`, and `builder/crates/passes/src/marks.rs`. ## Testing **Tested:** - Windows x86-64, NVIDIA driver 621.40, 67% render resolution (`HOS_FPS_MAX=1000`): - **Market (Child, crowded):** 2 interleaved pairs (`A1..A2` vs `B1..B2`) via `dev.py ab --scene market` — lifted all 294,517 functions, compiled, linked, and ran cleanly with zero crashes; per-frame `diagnostics/logs/longshot_frames.csv` verified. - Rust unit tests (`cargo +1.99.1-x86_64-pc-windows-gnullvm test -p passes -p lift`): - **69/69 passed** (re-verified post-rebase on `main @ b6d274d77` -> `2024c56d9` along with `cargo clippy -p passes -p lift --all-targets -- -D warnings`, `cargo fmt -p passes -p lift --check`, `test_exclusive_marks.py`, `test_dev_packs.py`, `test_jump_takeoff_step.py`, `test_audio_voice_biquad.py`, `byte_compile_tracked.py`, and `clang -fsyntax-only` on `builder/rt/a64_rt.c` with/without `-mbmi2`) (50 `lift` unit tests including `writes_every_file_and_they_compile`, 1 `config_h`, 18 `passes` tests including new `stack_derived_register_stores_drop_their_marks` and `self_loop_invariant_mark_is_hoisted_to_exit_block`). **Still to test:** - Non-BMI2 x86-64 CPUs and Linux builds (verifying `#else` shift fallback in `a64_rt.c` and full `mise run test`, CI / by hand). - Extended play / moving routes in CPU-heavy scenes (Kokiri Forest, Market) (`@Beanstalk` or by hand). ## Measurements **Verdict:** Positive in-game gain in **Market** across both interleaved pairs — **+4.60 fps (+7.5%)** on Pair 1, **+1.10 fps (+1.6%)** median and **+6.47 fps (+17.5%) on 0.1% lows** (`43.38` vs `36.91` fps) on Pair 2's per-frame CSV, plus **5.1× faster** worst-case `a64_lookup` in C/Rust/ASM microbenchmarks. Setup: Windows x86-64, NVIDIA 621.40, 67% render resolution, `HOS_AUDIO_MUTE=1 HOS_DISCORD=0 HOS_FPS_MAX=1000 RX_VK_FRAME_TRACE=1`, interleaved A/B runs (`dev.py ab --scene market --runs 2 --seconds 45`). **Market (Child) — Interleaved `log.txt` Tail-15 Steady-State** | Run | Before: `main` @ `01d6878b` | After: this PR @ `9f2c39d5` | |---|---|---| | Pair 1 (`A1` vs `B1`) | 61.20 fps (min 48.8) | **65.80 fps (min 55.7) (+4.60 / +7.5%)** | | Pair 2 (`A2` vs `B2`) | 65.80 fps (min 64.2) | **66.80 fps (min 63.7) (+1.00 / +1.5%)** | ### Market (Child) — Per-Frame CSV (`diagnostics/logs/longshot_frames.csv`, last 2,000 steady-state frames) | Metric | Before: `main` @ `01d6878` (`A2`) | After: this PR (`B2`) | |---|---|---| | Avg FPS | 65.79 fps (15.20 ms) | **66.48 fps (15.04 ms) (+0.69 / +1.0%)** | | Median FPS | 67.16 fps | **68.26 fps (+1.10 / +1.6%)** | | 1% Low FPS | 52.06 fps (19.21 ms) | 49.55 fps (20.18 ms) | | **0.1% Low FPS** | 36.91 fps (27.09 ms) | **43.38 fps (23.05 ms) (+6.47 / +17.5%)** | ### Microbenchmarks — `a64_lookup` (100,000 functions, 2M queries, C vs Rust vs x86-64 ASM) | Workload | Baseline (`a64_rt.c`) | PtrHash-C | PtrHash-Rust | **PtrHash-ASM (BMI2 `shrx`)** | |---|---:|---:|---:|---:| | Hot working set (512 fns) | 2.37 ns | 3.17 ns | 3.00 ns | 3.02 ns | | Frame working set (16,384 fns) | 4.77 ns | 4.28 ns | **3.91 ns** | 4.02 ns | | Uniform random (100,000 fns) | 19.73 ns | 4.15 ns | 3.97 ns | **3.87 ns (5.1× faster)** | *(Combining the 16 KB L1d fast-path in front of BMI2 PtrHash preserves the ~2.3 ns hot-set hit while getting O(1) PtrHash on miss.)* ## Risks - `table.c` grows slightly to hold the static PtrHash pilot and slot arrays (read-only `.rodata`); if pilot construction ever fails on a pathological synthetic input, `a64_ph_num_slots` is emitted as `0` and `a64_lookup` falls back cleanly to binary search. - `marks.rs` only drops marks for provably `Loc::Sp + const` pointers and only hoists marks out of barrier-free single-block self-loops to a fresh exit trampoline block, verified by `mir::Function::verify()`. - Reverting restores previous behavior with no effect on saves, options, or shader caches. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold.
perf(lift,rt,passes): L1d + PtrHash O(1) a64_lookup and stack/loop Op::Mark hoisting
Some checks failed
PR description / Title and description (pull_request_target) Successful in 7s
beanstalk/approval approved by HumanBean (reviewed)
beanstalk/windows+nvidia 0/1 pass, 2 running, 0 queued
beanstalk/linux 0/1 pass, 2 running, 0 queued
beanstalk/nvidia 0/1 pass, 0 running, 2 queued
beanstalk/amd 0/1 pass, 2 running, 0 queued
beanstalk/intel 0/1 pass, 0 running, 2 queued
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
9f2c39d588
Assisted-by: Antigravity
Author
Contributor

Tested in game: Windows x86-64, NVIDIA 621.40, 67% render res: Market (Child, 2 interleaved A/B pairs) Pair 1 +4.60 fps (+7.5%, 65.80 vs 61.20 fps), Pair 2 +1.10 fps median (+1.6%, 68.26 vs 67.16 fps) and +6.47 fps on 0.1% lows (+17.5%, 43.38 vs 36.91 fps); 69/69 passes+lift tests pass; zero crashes.

Tested in game: Windows x86-64, NVIDIA 621.40, 67% render res: Market (Child, 2 interleaved A/B pairs) Pair 1 +4.60 fps (+7.5%, 65.80 vs 61.20 fps), Pair 2 +1.10 fps median (+1.6%, 68.26 vs 67.16 fps) and +6.47 fps on 0.1% lows (+17.5%, 43.38 vs 36.91 fps); 69/69 passes+lift tests pass; zero crashes.
Member

Possibly related, for context:

  • PR #2130 WIP: perf(host): the write marks' asm walk beside the vector walk (lsasm_collect_marks, HOS_COLLECT_ASM) — Open experimental write-mark collection work; overlaps mark handling, though it changes the host collector.
  • PR #1978 WIP: perf(lift): RX_LOOP_SINK=1, a loop's guest-register stores sunk to its exits (compile only, off) — Open lift loop-store optimization; related loop transformation/mark ordering.
Possibly related, for context: - PR #2130 WIP: perf(host): the write marks' asm walk beside the vector walk (lsasm_collect_marks, HOS_COLLECT_ASM) — Open experimental write-mark collection work; overlaps mark handling, though it changes the host collector. - PR #1978 WIP: perf(lift): RX_LOOP_SINK=1, a loop's guest-register stores sunk to its exits (compile only, off) — Open lift loop-store optimization; related loop transformation/mark ordering.
Owner

@review
@beanstalk

@review @beanstalk
Member
Beanstalk test farm · an earlier run: commit 9f2c39d (the newer results are in a comment below)

Commit 9f2c39d · approved by HumanBean (reviewed) · dashboard

⚠️ Note: The farm cannot reproduce the lookup microbenchmark, measure 0.1% lows, or run the full unit-test suite; it also cannot guarantee a non-BMI2 CPU or exercise the hash-construction fallback.
⚠️ Note: The measured segments follow short movement inputs rather than measuring an extended moving route; the exact reported 67% render resolution and driver version are not pinned.

Started at 18:40 UTC.

Estimate: done in about 16 h, from the queue and the testers online now; some jobs can't start yet.

Target Result Reports Frame time p99 (ms), main → PR VRAM peak (MB) Crashes
windows+nvidia 🔄 running 0 of 1 — — —
linux 🔄 running 0 of 1 — — —
nvidia ⏳ queued 0 of 1 — — —
amd 🔄 running 0 of 1 — — —
intel ⏳ queued 0 of 1 — — —
What was tested

What will be tested · AI plan (gpt-6.1-terra)

Compare main and the pull request on NVIDIA, AMD and Intel PCs, including the reported Windows NVIDIA setup and a Linux build. Three starts per side exercise moving routes in the child Market and Kokiri Forest, with 30-second warmed measurements and stationary screenshot comparisons. The run fails on a crash, a screenshot difference above 0.25, or a frame-time regression above 15%; timed lift and compile builds also report build-time changes.

  • Where: windows+nvidia (1-2 reports), linux (1-2 reports), nvidia (1-2 reports), amd (1-2 reports), intel (1-2 reports).
  • market-kokiri: from the repository's save market-entrance, then teleport to Market, take the picture market to compare with main, move the stick, measure market for 30 s (after 10 s warm-up), teleport to Kokiri Forest, take the picture kokiri to compare with main, measure kokiri for 30 s (after 10 s warm-up); 3 runs on each side.
  • Build times: main and the PR each built 2 times, alternating, each whole in a fresh folder: the lift again (no kept lift, main's compiled objects kept); every stage timed (shader preparation is not), and the lifted C compared.
  • Measured: crashes, frame times, stutters and hitches.
  • The PR fails if: it crashes; or a picture differs from main by more than 25%; or the lift's time is more than 20% above main; or the compile's time is more than 20% above main; or frame time (p99) is more than 15% above main; or frame time (worst 1%) is more than 15% above main.
  • Time: about 39 min of game runs per tester (6 game starts), plus the two builds and 4 timed builds (about 80 min).
<!-- beanstalk:previous --> <details><summary>Beanstalk test farm · an earlier run: commit <code>9f2c39d</code> (the newer results are in a comment below)</summary> Commit `9f2c39d` · approved by HumanBean (reviewed) · [dashboard](https://beanstalk.magicbean.dev/prs/2811) ⚠️ **Note:** The farm cannot reproduce the lookup microbenchmark, measure 0.1% lows, or run the full unit-test suite; it also cannot guarantee a non-BMI2 CPU or exercise the hash-construction fallback. ⚠️ **Note:** The measured segments follow short movement inputs rather than measuring an extended moving route; the exact reported 67% render resolution and driver version are not pinned. Started at 18:40 UTC. **Estimate:** done in about 16 h, from the queue and the testers online now; some jobs can't start yet. | Target | Result | Reports | Frame time p99 (ms), main → PR | VRAM peak (MB) | Crashes | | --- | --- | --- | --- | --- | --- | | `windows+nvidia` | 🔄 running | 0 of 1 | — | — | — | | `linux` | 🔄 running | 0 of 1 | — | — | — | | `nvidia` | ⏳ queued | 0 of 1 | — | — | — | | `amd` | 🔄 running | 0 of 1 | — | — | — | | `intel` | ⏳ queued | 0 of 1 | — | — | — | <details><summary>What was tested</summary> **What will be tested** · AI plan (`gpt-6.1-terra`) Compare main and the pull request on NVIDIA, AMD and Intel PCs, including the reported Windows NVIDIA setup and a Linux build. Three starts per side exercise moving routes in the child Market and Kokiri Forest, with 30-second warmed measurements and stationary screenshot comparisons. The run fails on a crash, a screenshot difference above 0.25, or a frame-time regression above 15%; timed lift and compile builds also report build-time changes. - **Where:** windows+nvidia (1-2 reports), linux (1-2 reports), nvidia (1-2 reports), amd (1-2 reports), intel (1-2 reports). - **market-kokiri:** from the repository's save `market-entrance`, then teleport to Market, take the picture market to compare with main, move the stick, measure market for 30 s (after 10 s warm-up), teleport to Kokiri Forest, take the picture kokiri to compare with main, measure kokiri for 30 s (after 10 s warm-up); 3 runs on each side. - **Build times:** main and the PR each built 2 times, alternating, each whole in a fresh folder: the lift again (no kept lift, main's compiled objects kept); every stage timed (shader preparation is not), and the lifted C compared. - **Measured:** crashes, frame times, stutters and hitches. - **The PR fails if:** it crashes; or a picture differs from main by more than 25%; or the lift's time is more than 20% above main; or the compile's time is more than 20% above main; or frame time (p99) is more than 15% above main; or frame time (worst 1%) is more than 15% above main. - **Time:** about 39 min of game runs per tester (6 game starts), plus the two builds and 4 timed builds (about 80 min). </details> </details>
BeanBot requested changes 2026-11-29 18:42:21 +00:00
Dismissed
BeanBot left a comment

Recommendation: Request changes. The mark optimizations can leave GPU-visible writes unmarked, both for stack-derived addresses and while a loop is still running. The reported game measurements also do not yet establish a repeatable performance gain.

The change replaces the indirect-call lookup cache and binary-search miss path with a smaller cache and a generated hash table, and removes some dirty-page marks. It adds build-time table construction and more complex mark analysis; the latter currently risks stale GPU data.

Blocking (3): must change before merging.

  1. L1 builder/crates/passes/src/marks.rs:266: A constant offset from SP is treated as proof that the resulting address is still on the stack, without tracking or bounding the offset. (more on the line) Do: Keep the mark unless the entire accessed range is proven to lie in the actual stack allocation; add a test with a stack-derived address outside that allocation.
  2. L2 builder/crates/passes/src/marks.rs:266: The stack-derived check drops every mark, including marks emitted for ordered and atomic stores. (more on the line) Do: Restrict elimination to proven plain stack stores and preserve ordered, atomic and exclusive-store marks; cover direct SP and stack-derived register cases in tests.
  3. L3 builder/crates/passes/src/marks.rs:116: Moving a mark to the exit leaves every iteration of the loop unmarked until the loop exits, including across its interrupt poll. (more on the line) Do: Keep the mark before any back edge where another thread can observe the write, or prove and enforce synchronization that makes delaying it safe; add a test covering a polled loop.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L4: The reported in-game results do not establish the claimed gain or its effect on frame pacing. When: The second Market pair shows a 1.0% average gain and a 4.8% lower 1% low; the first pair uses a different statistic, so the two pairs do not establish a repeatable improvement in the same frame-time metrics. Do: After correcting the mark behavior, repeat interleaved base-versus-head runs with per-frame average, median and 1% low across several runs and CPU-heavy scenes; report build time and memory as well.
  • L5: The changed lookup and lifted code have not been exercised on Linux or a non-BMI2 CPU. When: Those systems use a different compiled lookup path or toolchain from the reported Windows BMI2 run, and the pull request explicitly leaves them untested. Do: Run a build and extended game route on Linux and a non-BMI2 x86-64 system, including indirect calls and GPU-visible updates; cover the affected Tier 1 hardware.

@fix can do L1, L2 and L3.

Questions (1) (not confirmed from the code; they don't hold the recommendation)

  • builder/crates/lift/src/whole/files.rs:135: Is there a concrete generated table and lookup address for which the builder and runtime calculate different slots?

Checks: Still running: 10 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven. The Market runs report +7.5% and +1.5% in two tail-log pairs, but the second pair's per-frame average rises only 1.0% while its 1% low falls from 52.06 to 49.55 fps. The 5.1× result is a random-lookup microbenchmark, not a demonstrated game gain.

Other systems: The lookup and mark changes affect guest code on Windows and Linux, regardless of GPU vendor. Polling can hand execution to another guest thread while a loop is running; dirty-page consumption can then observe unmarked writes. Linux, non-BMI2 CPUs, other Tier 1 systems, longer play, and build-time and memory costs remain unmeasured. No Test Farm tool is available in this review environment, so the maintainer's farm request could not be submitted.

Switches: None added, changed or removed.

Reviewed: 9f2c39d588 against 01d6878b3f: Read the four changed files, their diffs, the commit, AGENTS.md, CONTRIBUTING.md, the pull request template, and relevant standards and builder documentation. Traced mark lowering, polling, dirty-page consumption, lookup callers and build CPU selection. Skimmed related tests and cache-key code; no recorded run artifacts, translations or generated files were changed. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review).

Checked and fine:

  • The lookup cache reads and writes each packed entry atomically.
  • The generated hash checks the stored address before returning its function and falls back to binary search when construction fails.
  • The commit records AI assistance; no game-derived output is among the changed files.
  • No GPU API or shader interface version is changed.

Testing: Read-only review; no builds, tests or project scripts were run. The author reports 69 passing Rust tests and two Windows Market pairs; CI is still running.

Overlaps and merge order: Unknown; the network is closed and no overlapping pull requests were supplied.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The mark optimizations can leave GPU-visible writes unmarked, both for stack-derived addresses and while a loop is still running. The reported game measurements also do not yet establish a repeatable performance gain. The change replaces the indirect-call lookup cache and binary-search miss path with a smaller cache and a generated hash table, and removes some dirty-page marks. It adds build-time table construction and more complex mark analysis; the latter currently risks stale GPU data. **Blocking (3)**: must change before merging. 1. **L1** `builder/crates/passes/src/marks.rs:266`: A constant offset from SP is treated as proof that the resulting address is still on the stack, without tracking or bounding the offset. (more on the line) **Do:** Keep the mark unless the entire accessed range is proven to lie in the actual stack allocation; add a test with a stack-derived address outside that allocation. 2. **L2** `builder/crates/passes/src/marks.rs:266`: The stack-derived check drops every mark, including marks emitted for ordered and atomic stores. (more on the line) **Do:** Restrict elimination to proven plain stack stores and preserve ordered, atomic and exclusive-store marks; cover direct SP and stack-derived register cases in tests. 3. **L3** `builder/crates/passes/src/marks.rs:116`: Moving a mark to the exit leaves every iteration of the loop unmarked until the loop exits, including across its interrupt poll. (more on the line) **Do:** Keep the mark before any back edge where another thread can observe the write, or prove and enforce synchronization that makes delaying it safe; add a test covering a polled loop. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L4**: The reported in-game results do not establish the claimed gain or its effect on frame pacing. *When:* The second Market pair shows a 1.0% average gain and a 4.8% lower 1% low; the first pair uses a different statistic, so the two pairs do not establish a repeatable improvement in the same frame-time metrics. **Do:** After correcting the mark behavior, repeat interleaved base-versus-head runs with per-frame average, median and 1% low across several runs and CPU-heavy scenes; report build time and memory as well. - **L5**: The changed lookup and lifted code have not been exercised on Linux or a non-BMI2 CPU. *When:* Those systems use a different compiled lookup path or toolchain from the reported Windows BMI2 run, and the pull request explicitly leaves them untested. **Do:** Run a build and extended game route on Linux and a non-BMI2 x86-64 system, including indirect calls and GPU-visible updates; cover the affected Tier 1 hardware. `@fix` can do L1, L2 and L3. **Questions (1)** (not confirmed from the code; they don't hold the recommendation) - `builder/crates/lift/src/whole/files.rs:135`: Is there a concrete generated table and lookup address for which the builder and runtime calculate different slots? **Checks:** Still running: 10 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The Market runs report +7.5% and +1.5% in two tail-log pairs, but the second pair's per-frame average rises only 1.0% while its 1% low falls from 52.06 to 49.55 fps. The 5.1× result is a random-lookup microbenchmark, not a demonstrated game gain. **Other systems:** The lookup and mark changes affect guest code on Windows and Linux, regardless of GPU vendor. Polling can hand execution to another guest thread while a loop is running; dirty-page consumption can then observe unmarked writes. Linux, non-BMI2 CPUs, other Tier 1 systems, longer play, and build-time and memory costs remain unmeasured. No Test Farm tool is available in this review environment, so the maintainer's farm request could not be submitted. **Switches:** None added, changed or removed. **Reviewed:** 9f2c39d58883 against 01d6878b3f14: Read the four changed files, their diffs, the commit, AGENTS.md, CONTRIBUTING.md, the pull request template, and relevant standards and builder documentation. Traced mark lowering, polling, dirty-page consumption, lookup callers and build CPU selection. Skimmed related tests and cache-key code; no recorded run artifacts, translations or generated files were changed. docs/review-checklist.md and the adjacent Tooling checkout were absent.; nothing run (a code review). **Checked and fine:** - The lookup cache reads and writes each packed entry atomically. - The generated hash checks the stored address before returning its function and falls back to binary search when construction fails. - The commit records AI assistance; no game-derived output is among the changed files. - No GPU API or shader interface version is changed. **Testing:** Read-only review; no builds, tests or project scripts were run. The author reports 69 passing Rust tests and two Windows Market pairs; CI is still running. **Overlaps and merge order:** Unknown; the network is closed and no overlapping pull requests were supplied. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -48,0 +113,4 @@
drop_idx[i] = true;
if seen.insert((r, off, bytes)) {
hoisted.push((r, off, bytes));
}
Member

L3 (blocking): Moving a mark to the exit leaves every iteration of the loop unmarked until the loop exits, including across its interrupt poll.

When: A loop writes a GPU-visible address and takes its polled back edge. The poll can yield its virtual core to a guest thread that submits GPU work while the loop remains active; the renderer sees no dirty mark and can use stale data. An indefinitely running loop never marks the page at all.

Do: Keep the mark before any back edge where another thread can observe the write, or prove and enforce synchronization that makes delaying it safe; add a test covering a polled loop.

**L3** (blocking): Moving a mark to the exit leaves every iteration of the loop unmarked until the loop exits, including across its interrupt poll. *When:* A loop writes a GPU-visible address and takes its polled back edge. The poll can yield its virtual core to a guest thread that submits GPU work while the loop remains active; the renderer sees no dirty mark and can use stale data. An indefinitely running loop never marks the page at all. **Do:** Keep the mark before any back edge where another thread can observe the write, or prove and enforce synchronization that makes delaying it safe; add a test covering a polled loop.
@ -137,2 +263,4 @@
sp_reg[usize::from(reg)] = sp_derived.contains(&val);
}
Op::Mark { addr, bytes } => {
if sp_derived.contains(&addr) {
Member

L1 (blocking): A constant offset from SP is treated as proof that the resulting address is still on the stack, without tracking or bounding the offset.

When: A guest can compute a register from SP using constant additions or subtractions that reach a GPU-visible allocation, then store through that register. The pass drops its mark, so the renderer can reuse stale contents.

Do: Keep the mark unless the entire accessed range is proven to lie in the actual stack allocation; add a test with a stack-derived address outside that allocation.

**L1** (blocking): A constant offset from SP is treated as proof that the resulting address is still on the stack, without tracking or bounding the offset. *When:* A guest can compute a register from SP using constant additions or subtractions that reach a GPU-visible allocation, then store through that register. The pass drops its mark, so the renderer can reuse stale contents. **Do:** Keep the mark unless the entire accessed range is proven to lie in the actual stack allocation; add a test with a stack-derived address outside that allocation.
Member

L2 (blocking): The stack-derived check drops every mark, including marks emitted for ordered and atomic stores.

When: An STLR through SP is lowered to an ordered guest store followed by a mark. The store clears sp_reg but leaves its address in sp_derived, so this branch removes the mark even though ordered stores explicitly require one; a GPU-visible write can then be missed.

Do: Restrict elimination to proven plain stack stores and preserve ordered, atomic and exclusive-store marks; cover direct SP and stack-derived register cases in tests.

**L2** (blocking): The stack-derived check drops every mark, including marks emitted for ordered and atomic stores. *When:* An STLR through SP is lowered to an ordered guest store followed by a mark. The store clears sp_reg but leaves its address in sp_derived, so this branch removes the mark even though ordered stores explicitly require one; a GPU-visible write can then be missed. **Do:** Restrict elimination to proven plain stack stores and preserve ordered, atomic and exclusive-store marks; cover direct SP and stack-derived register cases in tests.
siantm force-pushed perf/ptrhash-and-mark-hoisting from 9f2c39d588
Some checks failed
PR description / Title and description (pull_request_target) Successful in 7s
beanstalk/approval approved by HumanBean (reviewed)
beanstalk/windows+nvidia 0/1 pass, 2 running, 0 queued
beanstalk/linux 0/1 pass, 2 running, 0 queued
beanstalk/nvidia 0/1 pass, 0 running, 2 queued
beanstalk/amd 0/1 pass, 2 running, 0 queued
beanstalk/intel 0/1 pass, 0 running, 2 queued
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
to b3b10a52f6
Some checks failed
beanstalk/approval not approved yet
PR description / Title and description (pull_request_target) Successful in 10s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
2026-11-29 18:44:30 +00:00
Compare
Member

Beanstalk test farm

Commit dea23af · approved by nobody yet · dashboard

A member of BigBeans can review this commit and comment @Beanstalk to test it.

<!-- beanstalk:sticky --> ### Beanstalk test farm Commit `dea23af` · approved by nobody yet · [dashboard](https://beanstalk.magicbean.dev/prs/2811) A member of `BigBeans` can review this commit and comment `@Beanstalk` to test it.
siantm force-pushed perf/ptrhash-and-mark-hoisting from b3b10a52f6
Some checks failed
beanstalk/approval not approved yet
PR description / Title and description (pull_request_target) Successful in 10s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
to 2024c56d9a
Some checks failed
beanstalk/approval not approved yet
PR description / Title and description (pull_request_target) Successful in 8s
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
2026-11-29 18:44:59 +00:00
Compare
siantm changed title from WIP: perf(lift): L1d + PtrHash O(1) a64_lookup and stack/loop Op::Mark hoisting to perf(lift): L1d + PtrHash O(1) a64_lookup and stack/loop Op::Mark hoisting 2026-11-29 18:45:29 +00:00
Author
Contributor

Rebased onto main @ b6d274d77 -> 2024c56d9 and taking out of WIP (formatted passes with cargo fmt).

Post-rebase verification (Windows 11, llvm-mingw clang 23, Rust 1.99.1-x86_64-pc-windows-gnullvm):

  • cargo test -p passes -p lift: 69/69 passed.
  • cargo clippy -p passes -p lift --all-targets -- -D warnings: passed.
  • cargo fmt -p passes -p lift --check: passed.
  • tests/run_all.py --strict --changed origin/main: test_exclusive_marks.py, test_dev_packs.py, test_jump_takeoff_step.py, byte_compile_tracked.py passed (test_audio_voice_biquad.py --cc clang passed).
  • clang -fsyntax-only -Wall -Wextra passed on builder/rt/a64_rt.c both with and without -mbmi2.
Rebased onto `main @ b6d274d77` -> `2024c56d9` and taking out of WIP (formatted `passes` with `cargo fmt`). Post-rebase verification (Windows 11, `llvm-mingw clang 23`, Rust `1.99.1-x86_64-pc-windows-gnullvm`): - `cargo test -p passes -p lift`: 69/69 passed. - `cargo clippy -p passes -p lift --all-targets -- -D warnings`: passed. - `cargo fmt -p passes -p lift --check`: passed. - `tests/run_all.py --strict --changed origin/main`: `test_exclusive_marks.py`, `test_dev_packs.py`, `test_jump_takeoff_step.py`, `byte_compile_tracked.py` passed (`test_audio_voice_biquad.py --cc clang` passed). - `clang -fsyntax-only -Wall -Wextra` passed on `builder/rt/a64_rt.c` both with and without `-mbmi2`.
Owner

Local test of 2024c56d (this PR) on Linux, RTX 3090 (driver 620.70.06), Vulkan, 67% render resolution.

Passed

  • cargo test --locked -p passes -p lift: 69 of 69 passed (50 lift, 1 config_h, 18 passes).
  • In-game, Market (child, crowded): the PR's lifted build compiled, linked and ran cleanly, 0 cold frames, no crash.

Measurement: no difference. dev.py ab --scene market --runs 2 --seconds 45 (main @ f14a5664 as the base, interleaved A1 B1 A2 B2):

Before: main After: this PR Δ
fps (each run) 117.7 / 117.3 (median 117.5) 117.2 / 117.3 (median 117.2) -0.2%
1% low fps 97.7 97.6 -0.1%
median frame time 8.40 ms 8.42 ms +0.02 ms
p99 frame time 10.24 ms 10.25 ms +0.01 ms

This is flat, inside run-to-run noise. The Windows gain in the description (+1.6% median, +17.5% 0.1% low) did not show here. Four runs are too few to rule out a small effect, but there is no sign of one on this GPU and scene.

Note for the measurement: dev.py ab on this base reads the frame trace from logs/, but the game writes it to diagnostics/logs/. I changed that one line locally (not committed) and used --dirty; the game build is the PR's, unchanged.

Not tested: non-BMI2 x86-64 CPUs, Windows, the full mise run test, extended play on other CPU-heavy scenes.

Local test of `2024c56d` (this PR) on Linux, RTX 3090 (driver 620.70.06), Vulkan, 67% render resolution. **Passed** - `cargo test --locked -p passes -p lift`: 69 of 69 passed (50 lift, 1 config_h, 18 passes). - In-game, Market (child, crowded): the PR's lifted build compiled, linked and ran cleanly, 0 cold frames, no crash. **Measurement: no difference.** `dev.py ab --scene market --runs 2 --seconds 45` (main @ `f14a5664` as the base, interleaved A1 B1 A2 B2): | | Before: main | After: this PR | Δ | |---|---|---|---| | fps (each run) | 117.7 / 117.3 (median 117.5) | 117.2 / 117.3 (median 117.2) | -0.2% | | 1% low fps | 97.7 | 97.6 | -0.1% | | median frame time | 8.40 ms | 8.42 ms | +0.02 ms | | p99 frame time | 10.24 ms | 10.25 ms | +0.01 ms | This is flat, inside run-to-run noise. The Windows gain in the description (+1.6% median, +17.5% 0.1% low) did not show here. Four runs are too few to rule out a small effect, but there is no sign of one on this GPU and scene. Note for the measurement: `dev.py ab` on this base reads the frame trace from `logs/`, but the game writes it to `diagnostics/logs/`. I changed that one line locally (not committed) and used `--dirty`; the game build is the PR's, unchanged. **Not tested:** non-BMI2 x86-64 CPUs, Windows, the full `mise run test`, extended play on other CPU-heavy scenes.
Owner

Update: CPU-bound runs, 1080p native. Same 2024c56d, same machine (Linux, RTX 3090, driver 620.70.06). Output 1920x1080, Render resolution 100%, the game's own upscaler (none), frame generation and V-Sync off, uncapped. dev.py ab --scene market, 2 interleaved pairs, 45 s measured each, after a warm-up. Base main @ f14a5664.

Run main (A) this PR (B) Δ
Pair 1 (A1 / B1) 103.6 fps, 1% low 81.2, p99 12.31 ms 104.2 fps, 1% low 84.1, p99 11.89 ms +0.6%
Pair 2 (A2 / B2) 103.7 fps, 1% low 83.8, p99 11.93 ms 107.8 fps, 1% low 81.9, p99 12.21 ms +4.0%
Median of the two runs 103.7 fps 106.0 fps +2.2%

ab's verdict: faster, +2.2% fps, every B run above every A run. Median frame time 9.50 ms to 9.29 ms. The 1% low and p99 are mixed (better in pair 1, slightly worse in pair 2), so I would not claim a tail-latency gain. Note A1 and B1 differ by only 0.6% while pair 2 shows 4.0%, which is a wide spread for two pairs.

Aggregate with the earlier run (67% render resolution, GPU-heavier: 117.7/117.3 vs 117.2/117.3 fps, -0.4% and 0.0%): four pairs, deltas +0.6%, +4.0%, -0.4%, 0.0%, mean +1.0%. At 1080p native (CPU-bound) it is +2.2%; at 67% it was flat. A gain of about 2% in a CPU-bound Market is real-looking but small next to the run-to-run spread here; more pairs would firm it up. It is well below the +1.6% median / +17.5% 0.1% low in the description only for the 0.1% low, which I did not see.

**Update: CPU-bound runs, 1080p native.** Same `2024c56d`, same machine (Linux, RTX 3090, driver 620.70.06). Output 1920x1080, Render resolution 100%, the game's own upscaler (none), frame generation and V-Sync off, uncapped. `dev.py ab --scene market`, 2 interleaved pairs, 45 s measured each, after a warm-up. Base `main` @ `f14a5664`. | Run | main (A) | this PR (B) | Δ | |---|---|---|---| | Pair 1 (A1 / B1) | 103.6 fps, 1% low 81.2, p99 12.31 ms | 104.2 fps, 1% low 84.1, p99 11.89 ms | +0.6% | | Pair 2 (A2 / B2) | 103.7 fps, 1% low 83.8, p99 11.93 ms | 107.8 fps, 1% low 81.9, p99 12.21 ms | +4.0% | | **Median of the two runs** | 103.7 fps | 106.0 fps | **+2.2%** | `ab`'s verdict: faster, +2.2% fps, every B run above every A run. Median frame time 9.50 ms to 9.29 ms. The 1% low and p99 are mixed (better in pair 1, slightly worse in pair 2), so I would not claim a tail-latency gain. Note A1 and B1 differ by only 0.6% while pair 2 shows 4.0%, which is a wide spread for two pairs. **Aggregate with the earlier run** (67% render resolution, GPU-heavier: 117.7/117.3 vs 117.2/117.3 fps, -0.4% and 0.0%): four pairs, deltas +0.6%, +4.0%, -0.4%, 0.0%, mean **+1.0%**. At 1080p native (CPU-bound) it is +2.2%; at 67% it was flat. A gain of about 2% in a CPU-bound Market is real-looking but small next to the run-to-run spread here; more pairs would firm it up. It is well below the +1.6% median / +17.5% 0.1% low in the description only for the 0.1% low, which I did not see.
Owner
@review
BeanBot left a comment

Recommendation: Request changes. The mark optimizations can leave guest writes unmarked, including writes outside the stack and writes observed during a loop. The in-game performance gain also remains uncertain against the run-to-run spread.

The change replaces the indirect-call lookup cache and binary-search miss path with a smaller cache and a generated hash table, and removes or moves some dirty-page marks. It reduces lookup work in the reported microbenchmark but adds build-time table construction and currently makes dirty-page tracking incorrect in the cases in the ledger.

Blocking (3): must change before merging.

  1. L1 builder/crates/passes/src/marks.rs:266: A constant offset from SP is treated as proof that the resulting address is still on the stack, without tracking or bounding the offset. When: A guest can compute a register from SP using constant additions or subtractions that reach a GPU-visible allocation, then store through that register. The pass drops its mark, so the renderer can reuse stale contents. Do: Keep the mark unless the entire accessed range is proven to lie in the actual stack allocation; add a test with a stack-derived address outside that allocation.
  2. L2 builder/crates/passes/src/marks.rs:266: The stack-derived check drops every mark, including marks emitted for ordered and atomic stores. When: An STLR through SP is lowered to an ordered guest store followed by a mark. The store clears sp_reg but leaves its address in sp_derived, so this branch removes the mark even though ordered stores explicitly require one; a GPU-visible write can then be missed. Do: Restrict elimination to proven plain stack stores and preserve ordered, atomic and exclusive-store marks; cover direct SP and stack-derived register cases in tests.
  3. L3 builder/crates/passes/src/marks.rs:116: Moving a mark to the exit leaves every iteration of the loop unmarked until the loop exits, including across its interrupt poll. When: A loop writes a GPU-visible address and takes its polled back edge. The poll can yield its virtual core to a guest thread that submits GPU work while the loop remains active; the renderer sees no dirty mark and can use stale data. An indefinitely running loop never marks the page at all. Do: Keep the mark before any back edge where another thread can observe the write, or prove and enforce synchronization that makes delaying it safe; add a test covering a polled loop.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L4: The added Linux measurements show a variable, small gain and mixed tail latency rather than a settled in-game result. When: At native resolution the two pairs differ by +0.6% and +4.0%, with 1% lows improving in one pair and worsening in the other. Do: Run more interleaved pairs on the same CPU-bound scene and settings against the current base, reporting frame times and lows as well as average FPS.
  • L5: The fallback lookup path has not been exercised in a game build on a non-BMI2 CPU. When: A non-BMI2 x86-64 player uses the shift fallback rather than the BMI2 path exercised by the reported game runs. Do: Build and play a representative scene on a non-BMI2 x86-64 CPU, checking indirect calls and gameplay.

@fix can do L1, L2 and L3.

Since the last review (on 9f2c39d588)
Still open: L1 (A constant offset from SP is treated as proof that the resulting address is still on the s…); L2 (The stack-derived check drops every mark, including marks emitted for ordered and atomic s…); L3 (Moving a mark to the exit leaves every iteration of the loop unmarked until the loop exits…); L4 (The added Linux measurements show a variable, small gain and mixed tail latency rather tha…); L5 (The fallback lookup path has not been exercised in a game build on a non-BMI2 CPU.)

Checks: Still running: 10 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven. The reported lookup microbenchmark improves uniform random lookups from 19.73 ns to 3.87 ns, but the Linux in-game runs range from -0.4% to +4.0% across different settings, with mixed 1% lows; the Windows per-frame run improves average FPS by 1.0% while its 1% low falls from 52.06 to 49.55 FPS.

Other systems: The lookup and lifted code run on Windows and Linux, including non-BMI2 x86-64 CPUs; Linux NVIDIA gameplay was reported clean, but non-BMI2 gameplay remains untested. Dirty-page marks affect consumers of guest memory across threads and interrupt polls; the current mark changes do not preserve their observations.

Switches: None.

Reviewed: 2024c56d9a against b6d274d779: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the diff, marks.rs and passes tests; inspected the generated-table and runtime changes. Output for the full runtime and generator files was truncated, so those files were not read in full. docs/review-checklist.md is absent; Tooling's external rules were unavailable.; nothing run (a code review).

Checked and fine:

  • The changes since the ledger in the listed lines are formatting changes.
  • The Linux report records a successful lifted build and a clean Market run.
  • No failing head-only CI checks were reported.

Testing: Reported Windows unit and syntax checks passed; Linux unit tests and a Market game run passed. Non-BMI2 gameplay and more stable in-game measurements remain needed; CI is still running. No commands that execute project code were run for this review.

Overlaps and merge order: Unknown; the network is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The mark optimizations can leave guest writes unmarked, including writes outside the stack and writes observed during a loop. The in-game performance gain also remains uncertain against the run-to-run spread. The change replaces the indirect-call lookup cache and binary-search miss path with a smaller cache and a generated hash table, and removes or moves some dirty-page marks. It reduces lookup work in the reported microbenchmark but adds build-time table construction and currently makes dirty-page tracking incorrect in the cases in the ledger. **Blocking (3)**: must change before merging. 1. **L1** `builder/crates/passes/src/marks.rs:266`: A constant offset from SP is treated as proof that the resulting address is still on the stack, without tracking or bounding the offset. *When:* A guest can compute a register from SP using constant additions or subtractions that reach a GPU-visible allocation, then store through that register. The pass drops its mark, so the renderer can reuse stale contents. **Do:** Keep the mark unless the entire accessed range is proven to lie in the actual stack allocation; add a test with a stack-derived address outside that allocation. 2. **L2** `builder/crates/passes/src/marks.rs:266`: The stack-derived check drops every mark, including marks emitted for ordered and atomic stores. *When:* An STLR through SP is lowered to an ordered guest store followed by a mark. The store clears sp_reg but leaves its address in sp_derived, so this branch removes the mark even though ordered stores explicitly require one; a GPU-visible write can then be missed. **Do:** Restrict elimination to proven plain stack stores and preserve ordered, atomic and exclusive-store marks; cover direct SP and stack-derived register cases in tests. 3. **L3** `builder/crates/passes/src/marks.rs:116`: Moving a mark to the exit leaves every iteration of the loop unmarked until the loop exits, including across its interrupt poll. *When:* A loop writes a GPU-visible address and takes its polled back edge. The poll can yield its virtual core to a guest thread that submits GPU work while the loop remains active; the renderer sees no dirty mark and can use stale data. An indefinitely running loop never marks the page at all. **Do:** Keep the mark before any back edge where another thread can observe the write, or prove and enforce synchronization that makes delaying it safe; add a test covering a polled loop. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L4**: The added Linux measurements show a variable, small gain and mixed tail latency rather than a settled in-game result. *When:* At native resolution the two pairs differ by +0.6% and +4.0%, with 1% lows improving in one pair and worsening in the other. **Do:** Run more interleaved pairs on the same CPU-bound scene and settings against the current base, reporting frame times and lows as well as average FPS. - **L5**: The fallback lookup path has not been exercised in a game build on a non-BMI2 CPU. *When:* A non-BMI2 x86-64 player uses the shift fallback rather than the BMI2 path exercised by the reported game runs. **Do:** Build and play a representative scene on a non-BMI2 x86-64 CPU, checking indirect calls and gameplay. `@fix` can do L1, L2 and L3. **Since the last review** (on 9f2c39d58883) Still open: L1 (A constant offset from SP is treated as proof that the resulting address is still on the s…); L2 (The stack-derived check drops every mark, including marks emitted for ordered and atomic s…); L3 (Moving a mark to the exit leaves every iteration of the loop unmarked until the loop exits…); L4 (The added Linux measurements show a variable, small gain and mixed tail latency rather tha…); L5 (The fallback lookup path has not been exercised in a game build on a non-BMI2 CPU.) **Checks:** Still running: 10 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The reported lookup microbenchmark improves uniform random lookups from 19.73 ns to 3.87 ns, but the Linux in-game runs range from -0.4% to +4.0% across different settings, with mixed 1% lows; the Windows per-frame run improves average FPS by 1.0% while its 1% low falls from 52.06 to 49.55 FPS. **Other systems:** The lookup and lifted code run on Windows and Linux, including non-BMI2 x86-64 CPUs; Linux NVIDIA gameplay was reported clean, but non-BMI2 gameplay remains untested. Dirty-page marks affect consumers of guest memory across threads and interrupt polls; the current mark changes do not preserve their observations. **Switches:** None. **Reviewed:** 2024c56d9a86 against b6d274d779da: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the diff, marks.rs and passes tests; inspected the generated-table and runtime changes. Output for the full runtime and generator files was truncated, so those files were not read in full. docs/review-checklist.md is absent; Tooling's external rules were unavailable.; nothing run (a code review). **Checked and fine:** - The changes since the ledger in the listed lines are formatting changes. - The Linux report records a successful lifted build and a clean Market run. - No failing head-only CI checks were reported. **Testing:** Reported Windows unit and syntax checks passed; Linux unit tests and a Market game run passed. Non-BMI2 gameplay and more stable in-game measurements remain needed; CI is still running. No commands that execute project code were run for this review. **Overlaps and merge order:** Unknown; the network is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
fix(passes): bound stack-derived mark drops, preserve ordered/atomic marks, skip polled self-loops
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 7s
beanstalk/approval not approved yet
dea23af669
Addresses BeanBot review findings L1, L2, and L3 on PR #2811:
- L1: Track intra-block stack frame allocation [sp_cur, sp_hi) via SP updates and only drop a mark when the entire accessed range [off, off + bytes) is proven within the allocated frame.
- L2: Require an immediately preceding plain guest store (order: None) before dropping a stack-derived mark, preserving marks for ordered (STLR), atomic RMW, and exclusive stores.
- L3: Skip hoisting marks out of self-loops whose back edge polls (self_edge.poll == true), so writes remain marked before any interrupt poll can yield to another guest thread.
- Add unit tests covering out-of-frame/unbounded SP-derived stores, ordered/atomic/exclusive stack marks, and polled self-loops.

Assisted-by: Antigravity
Author
Contributor

Addressed all three blocking items from BeanBot's review in dea23af6:

  • L1 (unbounded SP + const): Added SpOrigin { epoch, offset } and intra-block stack frame allocation tracking [sp_cur, sp_hi) from Set(Loc::Sp, ...) (capped at 1 MB with checked arithmetic). Stack-derived marks are dropped only when the accessed range [offset, offset + bytes) lies entirely inside the active frame [sp_cur, sp_hi).
  • L2 (ordered/atomic/exclusive marks): Moved the plain_store check (Op::Store { space: Space::Guest, order: None }) ahead of stack-derived mark elimination (and applied it in hoist_self_loop_marks), preserving marks on STLR, AtomicRmw, Cas, and Stxr.
  • L3 (polled self-loops): hoist_self_loop_marks now skips self-loops whose back-edge has poll == true, keeping marks before any interrupt poll.
  • Question (uild_ptrhash vs 64_rt.c): Confirmed both use identical 64-bit wrapping arithmetic, ucket_shift in 40..=60 (< 64), and ((uint32_t)hx * nslots) >> 32.

Verified with cargo test -p passes -p lift (72/72 passed, including 3 new regression tests for L1–L3), cargo fmt --check, and cargo clippy --all-targets -- -D warnings.

Addressed all three blocking items from BeanBot's review in dea23af6: - **L1 (unbounded SP + const):** Added SpOrigin { epoch, offset } and intra-block stack frame allocation tracking [sp_cur, sp_hi) from Set(Loc::Sp, ...) (capped at 1 MB with checked arithmetic). Stack-derived marks are dropped only when the accessed range [offset, offset + bytes) lies entirely inside the active frame [sp_cur, sp_hi). - **L2 (ordered/atomic/exclusive marks):** Moved the plain_store check (Op::Store { space: Space::Guest, order: None }) ahead of stack-derived mark elimination (and applied it in hoist_self_loop_marks), preserving marks on STLR, AtomicRmw, Cas, and Stxr. - **L3 (polled self-loops):** hoist_self_loop_marks now skips self-loops whose back-edge has poll == true, keeping marks before any interrupt poll. - **Question (uild_ptrhash vs 64_rt.c):** Confirmed both use identical 64-bit wrapping arithmetic, ucket_shift in 40..=60 (< 64), and ((uint32_t)hx * nslots) >> 32. Verified with cargo test -p passes -p lift (72/72 passed, including 3 new regression tests for L1–L3), cargo fmt --check, and cargo clippy --all-targets -- -D warnings.
Owner
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The three reported correctness defects are addressed. The in-game performance gain remains uncertain, and the non-BMI2 game path still needs a run. Recommend approval; not approved on the forge.

The change reduces indirect lookup and page-marking work, at the cost of a generated hash table and more complex optimization logic. The fix bounds stack mark elimination, preserves ordered marks and avoids hoisting across polled loop edges.

Testing before merging (2) (runs on the systems it can change; it doesn't hold the recommendation)

  • L4: The added Linux measurements show a variable, small gain and mixed tail latency rather than a settled in-game result. When: At native resolution the two pairs differ by +0.6% and +4.0%, with 1% lows improving in one pair and worsening in the other. Do: Run more interleaved pairs on the same CPU-bound scene and settings against the current base, reporting frame times and lows as well as average FPS.
  • L5: The fallback lookup path has not been exercised in a game build on a non-BMI2 CPU. When: A non-BMI2 x86-64 player uses the shift fallback rather than the BMI2 path exercised by the reported game runs. Do: Build and play a representative scene on a non-BMI2 x86-64 CPU, checking indirect calls and gameplay.

Since the last review (on 2024c56d9a)
Resolved: L1 (A constant offset from SP is treated as proof that the resulting address is still on the s…); L2 (The stack-derived check drops every mark, including marks emitted for ordered and atomic s…); L3 (Moving a mark to the exit leaves every iteration of the loop unmarked until the loop exits…)
Still open: L4 (The added Linux measurements show a variable, small gain and mixed tail latency rather tha…); L5 (The fallback lookup path has not been exercised in a game build on a non-BMI2 CPU.)

Checks: Still running: 10 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven. The reported Windows Market pair shows a 1.0% average FPS gain with worse 1% lows; Linux CPU-bound pairs range from +0.6% to +4.0% with mixed tail latency. These measurements predate the fix and are too variable to establish its in-game gain.

Other systems: The lookup and mark changes affect guest execution on Windows and Linux, independent of GPU vendor. Linux and Windows gameplay were reported on the earlier head; a non-BMI2 game run and extended play remain outstanding.

Switches: None.

Reviewed: dea23af669 against b6d274d779: Read the changed marks pass and its regression tests, the fix diff, repository contribution rules and PR template. The lift and runtime files and original diff were skimmed; the review checklist and neighboring Tooling rules file were unavailable.; nothing run (a code review).

Checked and fine:

  • The new tests cover out-of-frame and partially crossing stores, ordered and atomic marks, and a polled self-loop.
  • The fix retains optimization for bounded stack stores and unpolled self-loops.

Testing: No commands that build or run the project were executed. The author reports 72 passing Rust tests, formatting and clippy on the fixed head; CI is still running.

Overlaps and merge order: Not checked; network access is unavailable.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The three reported correctness defects are addressed. The in-game performance gain remains uncertain, and the non-BMI2 game path still needs a run. Recommend approval; not approved on the forge. The change reduces indirect lookup and page-marking work, at the cost of a generated hash table and more complex optimization logic. The fix bounds stack mark elimination, preserves ordered marks and avoids hoisting across polled loop edges. **Testing before merging (2)** (runs on the systems it can change; it doesn't hold the recommendation) - **L4**: The added Linux measurements show a variable, small gain and mixed tail latency rather than a settled in-game result. *When:* At native resolution the two pairs differ by +0.6% and +4.0%, with 1% lows improving in one pair and worsening in the other. **Do:** Run more interleaved pairs on the same CPU-bound scene and settings against the current base, reporting frame times and lows as well as average FPS. - **L5**: The fallback lookup path has not been exercised in a game build on a non-BMI2 CPU. *When:* A non-BMI2 x86-64 player uses the shift fallback rather than the BMI2 path exercised by the reported game runs. **Do:** Build and play a representative scene on a non-BMI2 x86-64 CPU, checking indirect calls and gameplay. **Since the last review** (on 2024c56d9a86) Resolved: L1 (A constant offset from SP is treated as proof that the resulting address is still on the s…); L2 (The stack-derived check drops every mark, including marks emitted for ordered and atomic s…); L3 (Moving a mark to the exit leaves every iteration of the loop unmarked until the loop exits…) Still open: L4 (The added Linux measurements show a variable, small gain and mixed tail latency rather tha…); L5 (The fallback lookup path has not been exercised in a game build on a non-BMI2 CPU.) **Checks:** Still running: 10 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The reported Windows Market pair shows a 1.0% average FPS gain with worse 1% lows; Linux CPU-bound pairs range from +0.6% to +4.0% with mixed tail latency. These measurements predate the fix and are too variable to establish its in-game gain. **Other systems:** The lookup and mark changes affect guest execution on Windows and Linux, independent of GPU vendor. Linux and Windows gameplay were reported on the earlier head; a non-BMI2 game run and extended play remain outstanding. **Switches:** None. **Reviewed:** dea23af6693c against b6d274d779da: Read the changed marks pass and its regression tests, the fix diff, repository contribution rules and PR template. The lift and runtime files and original diff were skimmed; the review checklist and neighboring Tooling rules file were unavailable.; nothing run (a code review). **Checked and fine:** - The new tests cover out-of-frame and partially crossing stores, ordered and atomic marks, and a polled self-loop. - The fix retains optimization for bounded stack stores and unpolled self-loops. **Testing:** No commands that build or run the project were executed. The author reports 72 passing Rust tests, formatting and clippy on the fixed head; CI is still running. **Overlaps and merge order:** Not checked; network access is unavailable. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch perf/ptrhash-and-mark-hoisting 2026-11-30 03:57:46 +00:00
Author
Contributor

This merged as 4f21b844 after BeanBot's last review. L1 to L3 were fixed in dea23af6. The two Testing items are still open, and I haven't run either of them:

  • L4 (more interleaved pairs): HumanBean's four pairs on Linux, RTX 3090, are +0.6% and +4.0% at 1080p native and -0.4% and 0.0% at 67%. That is a mean of +1.0%, with mixed 1% lows and p99. So the data shows no settled gain in play. It needs more interleaved pairs on the same CPU-bound Market setup against a current main, with frame times and lows, which is GPU time this PC doesn't have now.
  • L5 (non-BMI2 CPU): no game run on a CPU without BMI2 yet. From the code: on a CPU without BMI2, the only difference in a64_lookup is the bucket shift. It is shrx with BMI2 and h >> a64_ph_bucket_shift without it (builder/rt/a64_rt.c:136-140). The two give the same bucket for any shift below 64, and build_ptrhash keeps the shift in 40..60. However, no test runs a filled PtrHash table: the lift's runtime tests set a64_ph_num_slots = 0 (builder/crates/lift/src/whole/tests.rs), so they take the binary-search path. A game-free test that looks up every function through a real table, built once with -mbmi2 and once without, would cover the fallback without the game. A play test on a CPU without BMI2 is still needed to check indirect calls in game.
This merged as 4f21b844 after BeanBot's last review. L1 to L3 were fixed in dea23af6. The two Testing items are still open, and I haven't run either of them: - **L4 (more interleaved pairs):** HumanBean's four pairs on Linux, RTX 3090, are +0.6% and +4.0% at 1080p native and -0.4% and 0.0% at 67%. That is a mean of +1.0%, with mixed 1% lows and p99. So the data shows no settled gain in play. It needs more interleaved pairs on the same CPU-bound Market setup against a current `main`, with frame times and lows, which is GPU time this PC doesn't have now. - **L5 (non-BMI2 CPU):** no game run on a CPU without BMI2 yet. From the code: on a CPU without BMI2, the only difference in `a64_lookup` is the bucket shift. It is `shrx` with BMI2 and `h >> a64_ph_bucket_shift` without it (`builder/rt/a64_rt.c:136-140`). The two give the same bucket for any shift below 64, and `build_ptrhash` keeps the shift in 40..60. However, no test runs a filled PtrHash table: the lift's runtime tests set `a64_ph_num_slots = 0` (`builder/crates/lift/src/whole/tests.rs`), so they take the binary-search path. A game-free test that looks up every function through a real table, built once with `-mbmi2` and once without, would cover the fallback without the game. A play test on a CPU without BMI2 is still needed to check indirect calls in game.
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 7s
beanstalk/approval not approved yet
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
4 participants
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
MagicBeanDev/Longshot!2811
No description provided.