D3D12-SHADER-ITE-LOSSY-MEMO: keep the results of Bools::ite in a table that forgets (-12 % of full-archive translate time) #2773

Merged
bobcatchris merged 1 commit from upstream-pr/2773 into main 2026-11-30 20:12:33 +00:00
bobcatchris commented 2026-11-30 18:01:37 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-11-30T18:01:37Z.


Claim: D3D12-SHADER-ITE-LOSSY-MEMO (claim in #2570).

What

Bools::ite in leonida-shader/src/structure.rs, the core of the lane-mask structuriser, kept every result in a hash map. A result depends on its triple alone, and the nodes made on the way to it stay in the diagram, so a result that is asked for again after it was dropped finds those nodes and makes none: the table can forget without the diagram, its node numbers or anything built from them changing.

The results now live in IteCache, a set-associative table of four 16-byte entries to a 64-byte line (newest of a set first). It doubles, keeping what it holds, while the diagram has more nodes than it has entries, up to one entry per possible node (MAX_NODES). A lookup touches one line (a hash map touches its control bytes and then the entry), and nothing is rehashed one entry at a time as it grows.

Bools::mk also makes a new node with one probe of unique (entry) where it looked the key up and then inserted it.

Safe Rust, no new dependency, no change to what any caller sees.

Measured

leonida translate of the whole archive, 16 threads on a Ryzen 7 7800X3D, built with --features diagnostics,mimalloc (the build the game uses), four interleaved pairs of this branch against main (08e42a516), final code:

wall CPU (user + kernel)
main 46.5, 46.5, 47.1, 48.3 s (mean 47.1) 653.5, 652.9, 653.5, 657.0 s (mean 654.2)
this branch 40.9, 41.3, 40.6, 41.9 s (mean 41.2) 572.1, 575.5, 572.3, 576.4 s (mean 574.1)

That is -12.5 % wall and -12.2 % CPU.

Sizing the table (measured with the first version of the index function, two runs of each): as many entries as nodes was the best of six settings; twice and four times as many entries as nodes, and a half, a quarter and an eighth as many, used 3 % to 19 % more user CPU.

DXIL is unchanged. Every emitted DXIL was hashed (blake3) and compared with a main binary built the same way: 25,689 programs, 15,799 distinct, the same multiset in all four runs of this branch.

Where it does not help: with the system heap (cargo build --release -p leonida, the build of README-fxceless.md) and 16 threads I measured no change: six interleaved pairs, CPU 908 s on main and 913 s here (+0.5 %, inside the run-to-run spread of the machine, which was busy: walls from 66 to 94 s). The translator on that build waits on the allocator, so time taken out of the diagram work does not show. I did not find out more than that.

Tests

cargo test -p leonida-shader --release: 388 passed, 5 ignored. New:

  • the_memo_keeps_the_newest_results_of_a_set_and_forgets_the_rest: of ten results put into one set, the last four are found, no other triple is.
  • the_memo_grows_to_its_limit_and_keeps_what_it_holds.
  • a_memo_that_forgets_gives_the_nodes_one_that_keeps_all_gives: 400 random and/or/xor/not/ite over 8 variables on three diagrams (default memo, a memo of four entries that cannot grow, one with room for all): the same node at every step, the same node list at the end, and every function checked against its truth table over all 256 assignments. Asking the small one the whole script again makes no node.

Negative controls: a lookup that ignores the third key of the triple, an insert that does not push the older entries down, a growth that drops its entries and a growth that ignores its limit each make at least one of them fail (I made each change, ran them, and reverted it).

Not in this pull request

Nothing from the game: no archive, shader, hash or log is in it, and scripts/check_no_game_data.py is clean on the one file. It does not touch my open #2726 (Bools::given), which edits other lines of the same file; whichever merges second takes a merge.

AI-assisted: Claude Sonnet 5.5. Measured on an RX 7900 XTX machine (no GPU is used by translate).

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5570861223 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2773). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-11-30T18:01:37Z. --- Claim: D3D12-SHADER-ITE-LOSSY-MEMO ([claim](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7286017923) in #2570). ## What `Bools::ite` in `leonida-shader/src/structure.rs`, the core of the lane-mask structuriser, kept every result in a hash map. A result depends on its triple alone, and the nodes made on the way to it stay in the diagram, so a result that is asked for again after it was dropped finds those nodes and makes none: the table can forget without the diagram, its node numbers or anything built from them changing. The results now live in `IteCache`, a set-associative table of four 16-byte entries to a 64-byte line (newest of a set first). It doubles, keeping what it holds, while the diagram has more nodes than it has entries, up to one entry per possible node (`MAX_NODES`). A lookup touches one line (a hash map touches its control bytes and then the entry), and nothing is rehashed one entry at a time as it grows. `Bools::mk` also makes a new node with one probe of `unique` (`entry`) where it looked the key up and then inserted it. Safe Rust, no new dependency, no change to what any caller sees. ## Measured `leonida translate` of the whole archive, 16 threads on a Ryzen 7 7800X3D, built with `--features diagnostics,mimalloc` (the build the game uses), four interleaved pairs of this branch against main (`08e42a516`), final code: | | wall | CPU (user + kernel) | |---|---|---| | main | 46.5, 46.5, 47.1, 48.3 s (mean 47.1) | 653.5, 652.9, 653.5, 657.0 s (mean 654.2) | | this branch | 40.9, 41.3, 40.6, 41.9 s (mean 41.2) | 572.1, 575.5, 572.3, 576.4 s (mean 574.1) | That is -12.5 % wall and -12.2 % CPU. Sizing the table (measured with the first version of the index function, two runs of each): as many entries as nodes was the best of six settings; twice and four times as many entries as nodes, and a half, a quarter and an eighth as many, used 3 % to 19 % more user CPU. **DXIL is unchanged.** Every emitted DXIL was hashed (blake3) and compared with a main binary built the same way: 25,689 programs, 15,799 distinct, the same multiset in all four runs of this branch. **Where it does not help:** with the system heap (`cargo build --release -p leonida`, the build of `README-fxceless.md`) and 16 threads I measured no change: six interleaved pairs, CPU 908 s on main and 913 s here (+0.5 %, inside the run-to-run spread of the machine, which was busy: walls from 66 to 94 s). The translator on that build waits on the allocator, so time taken out of the diagram work does not show. I did not find out more than that. ## Tests `cargo test -p leonida-shader --release`: 388 passed, 5 ignored. New: - `the_memo_keeps_the_newest_results_of_a_set_and_forgets_the_rest`: of ten results put into one set, the last four are found, no other triple is. - `the_memo_grows_to_its_limit_and_keeps_what_it_holds`. - `a_memo_that_forgets_gives_the_nodes_one_that_keeps_all_gives`: 400 random `and`/`or`/`xor`/`not`/`ite` over 8 variables on three diagrams (default memo, a memo of four entries that cannot grow, one with room for all): the same node at every step, the same node list at the end, and every function checked against its truth table over all 256 assignments. Asking the small one the whole script again makes no node. Negative controls: a lookup that ignores the third key of the triple, an insert that does not push the older entries down, a growth that drops its entries and a growth that ignores its limit each make at least one of them fail (I made each change, ran them, and reverted it). ## Not in this pull request Nothing from the game: no archive, shader, hash or log is in it, and `scripts/check_no_game_data.py` is clean on the one file. It does not touch my open #2726 (`Bools::given`), which edits other lines of the same file; whichever merges second takes a merge. AI-assisted: Claude Sonnet 5.5. Measured on an RX 7900 XTX machine (no GPU is used by `translate`).
OreoFR commented 2026-11-30 18:06:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T18:06:08Z.


Verified by OreoFR on macOS 27.2.1, Apple M5, Rust (rustup), main ad36782c6 merged with head 6bbaeed11.

  • MEASURED, cargo test --release -p leonida-shader: main 229 passed, 0 failed, 2 ignored; main + this PR 232 passed, 0 failed, 2 ignored. The 3 new tests are the_memo_keeps_the_newest_results_of_a_set_and_forgets_the_rest, the_memo_grows_to_its_limit_and_keeps_what_it_holds and a_memo_that_forgets_gives_the_nodes_one_that_keeps_all_gives (the last one checks the forgetting memo against one that keeps everything).
  • No red side: the new tests exercise the new memo type, so they cannot run against main's code.
  • Not covered here: the Windows-only test modules of the crate (#[cfg(all(test, windows))]), the output identity over the archive and the -12 % translate time (they need the game's shaders).

AI-assisted: Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7287349240 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2773#issuecomment-7287349240). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T18:06:08Z. --- Verified by OreoFR on macOS 27.2.1, Apple M5, Rust (rustup), `main` `ad36782c6` merged with head `6bbaeed11`. - MEASURED, `cargo test --release -p leonida-shader`: `main` 229 passed, 0 failed, 2 ignored; `main` + this PR 232 passed, 0 failed, 2 ignored. The 3 new tests are `the_memo_keeps_the_newest_results_of_a_set_and_forgets_the_rest`, `the_memo_grows_to_its_limit_and_keeps_what_it_holds` and `a_memo_that_forgets_gives_the_nodes_one_that_keeps_all_gives` (the last one checks the forgetting memo against one that keeps everything). - No red side: the new tests exercise the new memo type, so they cannot run against `main`'s code. - Not covered here: the Windows-only test modules of the crate (`#[cfg(all(test, windows))]`), the output identity over the archive and the -12 % translate time (they need the game's shaders). AI-assisted: Claude Code
KelboLive commented 2026-11-30 18:19:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T18:19:03Z.


Independent check on Windows (not the author), at 6bbaeed11.

  • cargo test --locked -p leonida-shader --lib (shared warm target): 388 passed, 0 failed, 5 ignored in 273.7 s.

The -12% translate-time claim needs a corpus run, which I did not do; the crate's structural tests are green with the memo table.

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned.

AI-assisted: yes (opencode).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7287668068 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2773#issuecomment-7287668068). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T18:19:03Z. --- Independent check on Windows (not the author), at `6bbaeed11`. - `cargo test --locked -p leonida-shader --lib` (shared warm target): **388 passed, 0 failed, 5 ignored** in 273.7 s. The -12% translate-time claim needs a corpus run, which I did not do; the crate's structural tests are green with the memo table. Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711, Rust 1.98.1 pinned. AI-assisted: yes (opencode).
MoonEyes commented 2026-11-30 20:11:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T20:11:39Z.


RUN · VERIFY-2773-RTX4060 · by MoonEyes (another person than the author) on head 6bbaeed11, with #2745 (88d0dbf9c), #2773 (6bbaeed11), #2726 (986771506) and #2780 (6c4474cfd) merged into main 51dbc5b58. Windows 11 Pro 26300, RTX 4060 8 GB, -SeriesS -FrameGen 2, diag build.

  • cargo test -p leonida-shader --locked: 400 passed; -p leonida-gpu: 580 passed; 0 failed.
  • Game: two runs of 480 s, the person walking in the world from 345 s. First (shaders translated again: 132 s, pipelines warmed: 533 s): steady after 98 s, about 500 s of it. Second, warm: steady after 107 s, about 495 s of it, about 51 m walked. In both no device loss, no unhandled exception, the process alive at the end. PASS for the gate of 300 s. The picture was not looked at.
  • Translation at a first start 132 s here, 177 s on main 8f41d7d01 with two other pull requests: n=1 on each side and not the same tree, so no speed-up is claimed. The four pull requests were in one build.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7290547696 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2773#issuecomment-7290547696). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T20:11:39Z. --- RUN · VERIFY-2773-RTX4060 · by MoonEyes (another person than the author) on head `6bbaeed11`, with #2745 (`88d0dbf9c`), #2773 (`6bbaeed11`), #2726 (`986771506`) and #2780 (`6c4474cfd`) merged into `main` `51dbc5b58`. Windows 11 Pro 26300, RTX 4060 8 GB, `-SeriesS -FrameGen 2`, diag build. - `cargo test -p leonida-shader --locked`: 400 passed; `-p leonida-gpu`: 580 passed; 0 failed. - Game: two runs of 480 s, the person walking in the world from 345 s. First (shaders translated again: 132 s, pipelines warmed: 533 s): steady after 98 s, about 500 s of it. Second, warm: steady after 107 s, about 495 s of it, about 51 m walked. In both no device loss, no unhandled exception, the process alive at the end. PASS for the gate of 300 s. The picture was not looked at. - Translation at a first start 132 s here, 177 s on `main` `8f41d7d01` with two other pull requests: n=1 on each side and not the same tree, so no speed-up is claimed. The four pull requests were in one build. AI-assisted (Claude Code).
MoonEyes commented 2026-11-30 20:12:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-30T20:12:29Z.


Merging. Head 6bbaeed11 merges cleanly with main b7934269d and does not force a rebase of #2566. Two runs in the game (RTX 4060, about 500 s steady each, no device loss) with #2745, #2773, #2726 and #2780 together on this head; cargo test green; checked by other people. The shaders are translated again at the first start. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7290567688 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2773#issuecomment-7290567688). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-30T20:12:29Z. --- Merging. Head `6bbaeed11` merges cleanly with `main` `b7934269d` and does not force a rebase of #2566. Two runs in the game (RTX 4060, about 500 s steady each, no device loss) with #2745, #2773, #2726 and #2780 together on this head; cargo test green; checked by other people. The shaders are translated again at the first start. Merged by MoonEyes. AI-assisted (Claude Code).
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
ProjectLeonida/mandy!2773
No description provided.