native: follow each wrapped range once per pass, not once per heap entry (follow-up to #267) #319

Manually merged
github merged 1 commit from github-bot/gh-319 into main 2026-11-27 13:38:57 +00:00 AGit
Owner

@⁠Olima34 on GitHub · 2026-11-27 11:16 UTC · original
Olima34:fix/follow-memo → main · +161 −2 · 4 files · 1 commits · merged 2026-11-27 13:35 UTC

Follow-up to #267 (Refs #258), answering the cost question asked there.

What it cost. follow_title_pages checked each heap entry's signature on its own. But the title copies the same descriptor into many slots of the shader-visible heap. At the 1,000th pass of a world run, we followed 696 large entries:

  • 54 copies of the 174 MiB range;
  • 12 of the 50 MiB range;
  • 59 of a 24 MiB range;
  • 571 of a 21 MB host-memory view.

So each pass walked the same mappings dozens of times, under the pool-table lock.

Fix. Within one pass, the signature is computed once per distinct (base, end) range and reused for every entry over it.

Numbers (M5 Pro, release). These come from an #[ignore] harness with that entry mix, synthetic addresses and sizes, and 1,000, 10,000 or 100,000 other one-page mappings in the table, in the common case where the generation changed but nothing under the views did:

Other mappings Before After
1,000 2,970 µs 71 µs
10,000 2,875 µs 71 µs
100,000 3,298 µs 78 µs

The cost per range is linear in the mappings under it: 13–28 ns each (the 174 MiB range is 36–78 µs). The table's other mappings barely matter, since the lookup is log n.

That world run made about 12 passes a second: 900 in 73 s. The pool table changes about 2,600 times a second, but a pass happens only once per submission. So the cost drops from about 37 ms of CPU a second, with the pool lock held about 3 ms per pass, to under 1 ms a second.

Tests:

  • native::tests::copies_of_a_wrapped_view_are_followed_with_one_walk: three copies of a wrapped view, then a change elsewhere in the table, make 1 signature walk instead of 3. Without the memo the test fails (3 vs 1). After a remap under the view it is still 1 walk, and the copy the program reads follows the remap, checked on the GPU.
  • The harness stays as memory::signature_timing::signature_walks_of_a_follow_pass (#[ignore]), documented as a regression measure with the command to run it.

Checks: victory-gpu 320 tests pass (2 ignored), Windows clippy is clean with -D warnings, cargo xtask policy passes, and docs/native-host.md is updated.

Later, if needed: a per-range generation in PoolTable, so a pass only re-walks ranges a change touched.

**@⁠Olima34** on GitHub · 2026-11-27 11:16 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/319) `Olima34:fix/follow-memo` → `main` · +161 −2 · 4 files · 1 commits · merged 2026-11-27 13:35 UTC Follow-up to #267 (Refs #258), answering the cost question asked there. **What it cost.** `follow_title_pages` checked each heap entry's signature on its own. But the title copies the same descriptor into many slots of the shader-visible heap. At the 1,000th pass of a world run, we followed 696 large entries: - 54 copies of the 174 MiB range; - 12 of the 50 MiB range; - 59 of a 24 MiB range; - 571 of a 21 MB host-memory view. So each pass walked the same mappings dozens of times, under the pool-table lock. **Fix.** Within one pass, the signature is computed once per distinct `(base, end)` range and reused for every entry over it. **Numbers** (M5 Pro, release). These come from an `#[ignore]` harness with that entry mix, synthetic addresses and sizes, and 1,000, 10,000 or 100,000 other one-page mappings in the table, in the common case where the generation changed but nothing under the views did: | Other mappings | Before | After | |---|---|---| | 1,000 | 2,970 µs | 71 µs | | 10,000 | 2,875 µs | 71 µs | | 100,000 | 3,298 µs | 78 µs | The cost per range is linear in the mappings under it: 13–28 ns each (the 174 MiB range is 36–78 µs). The table's other mappings barely matter, since the lookup is log n. That world run made about 12 passes a second: 900 in 73 s. The pool table changes about 2,600 times a second, but a pass happens only once per submission. So the cost drops from about 37 ms of CPU a second, with the pool lock held about 3 ms per pass, to under 1 ms a second. **Tests:** - `native::tests::copies_of_a_wrapped_view_are_followed_with_one_walk`: three copies of a wrapped view, then a change elsewhere in the table, make 1 signature walk instead of 3. Without the memo the test fails (3 vs 1). After a remap under the view it is still 1 walk, and the copy the program reads follows the remap, checked on the GPU. - The harness stays as `memory::signature_timing::signature_walks_of_a_follow_pass` (`#[ignore]`), documented as a regression measure with the command to run it. **Checks:** victory-gpu 320 tests pass (2 ignored), Windows clippy is clean with `-D warnings`, `cargo xtask policy` passes, and `docs/native-host.md` is updated. Later, if needed: a per-range generation in `PoolTable`, so a pass only re-walks ranges a change touched.
Refs #258

Follow-up to #267. The title copies one view into many heap entries: at
the 1,000th look of a world run, follow_title_pages checked 54 copies of
the 174 MiB view, 12 of the 50 MiB one and 59 of a 24 MiB one, each
walking the pool table for its signature with the table locked. A look
like that one takes 2.7-3.1 ms (M5 Pro), at about 12 looks a second.

A look now walks each distinct range once and reuses the result for
the other entries over it: 60-90 us for the same look.

Regression measure: memory::signature_timing::
signature_walks_of_a_follow_pass, an ignored test run by hand in
release, times the walks over a synthetic pool table laid out like the
world's (the 174 MiB view as 2,784 one-page mappings over three
non-adjacent runs of pool pages, the 50 and 24 MiB ones, and 1,000 to
100,000 other mappings). A walk costs 13-28 ns a mapping under its range;
the other mappings barely count.

Test: tests::copies_of_a_wrapped_view_are_followed_with_one_walk: three
copies of a wrapped view take one walk a look (three before), and the
copy a program reads still follows a remap under it.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 11:17:45 +00:00
Author
Owner

@⁠LakshanSivakumar on GitHub · 2026-11-27 11:54 UTC · original

Thank you for answering the cost question with a table and a test. A pass that walks each range once is a clear improvement, and I agree with the memo being per pass.

I have not run it. I will include it in my next combined run (with #263, #264, #253 and #278) and say what the run shows. One request: in the description, point to the world run the "696 large entries" were counted in (commit and switches), so I can compare against my own.

**@⁠LakshanSivakumar** on GitHub · 2026-11-27 11:54 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/319#issuecomment-7217608732) Thank you for answering the cost question with a table and a test. A pass that walks each range once is a clear improvement, and I agree with the memo being per pass. I have not run it. I will include it in my next combined run (with #263, #264, #253 and #278) and say what the run shows. One request: in the description, point to the world run the "696 large entries" were counted in (commit and switches), so I can compare against my own.
Author
Owner

@⁠Olima34 on GitHub · 2026-11-27 12:40 UTC · original

The "696 large entries" come from this world run (M5 Pro 48 GB, Series S, windowed, 300 s):

  • The log line is following the title's pages under heap buffer views looks=1000 generation=321276, at 09:38:37Z.
  • The build is c1b95875 + #253 (first head, 8ebef857) + #264 (5ec1d4e7) + #267's revision. That revision was a WIP commit with the same code as ca22c393, apart from docs.
  • Switches: VICTORY_TRACE_TARGETS=1, VICTORY_DUMP_TARGETS=<dir>,110,20, and VICTORY_KEYS pressing Enter every 3 s, via run-native.sh --seconds 300 --console series-s.
**@⁠Olima34** on GitHub · 2026-11-27 12:40 UTC · [original](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/319#issuecomment-7218531381) The "696 large entries" come from this world run (M5 Pro 48 GB, Series S, windowed, 300 s): - The log line is `following the title's pages under heap buffer views looks=1000 generation=321276`, at 09:38:37Z. - The build is c1b95875 + #253 (first head, 8ebef857) + #264 (5ec1d4e7) + #267's revision. That revision was a WIP commit with the same code as ca22c393, apart from docs. - Switches: `VICTORY_TRACE_TARGETS=1`, `VICTORY_DUMP_TARGETS=<dir>,110,20`, and `VICTORY_KEYS` pressing Enter every 3 s, via `run-native.sh --seconds 300 --console series-s`.
github manually merged commit 4363be938f into main 2026-11-27 13:38:57 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.