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

Merged
Olima34 merged 1 commit from upstream-pr/319 into main 2026-11-27 13:35:46 +00:00
Olima34 commented 2026-11-27 11:16:05 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T11:16:05Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:5525702309 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/319). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T11:16:05Z. --- 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.
LakshanSivakumar commented 2026-11-27 11:54:15 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-27T11:54:15Z.


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.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7217608732 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/319#issuecomment-7217608732). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-27T11:54:15Z. --- 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.
Olima34 commented 2026-11-27 12:40:11 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by Olima34 on 2026-11-27T12:40:11Z.


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.
<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7218531381 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/319#issuecomment-7218531381). Originally posted by [Olima34](https://github.com/Olima34) on 2026-11-27T12:40:11Z. --- 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`.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
LakshanSivakumar/Native-Victory-macOS!319
No description provided.