Gate Matrix visual reconstruction on actual symbol or color swaps
perfloop/ttfx · ALLOCATION HOT LOOP
https://perfloop.ai/t/oss/case_k2wf9rs78a
Verdict
VERIFIED · settled 2026-08-11
What happened: The paired measurements met the required improvement.
Hypothesis
`Matrix::next_frame` invokes `RainColumn::tick` for every active column on every emitted frame, and the tick’s visible-character loop unconditionally calls `set_appearance` after its two swap-probability draws. At the default 0.005 symbol and 0.001 color probabilities, both draws miss on roughly 99.4% of visits, but those misses still clone the current symbol and color, copy the input symbol in the helper, and make `Animation::set_appearance` allocate a new `Rc<CharacterVisual>`, derive color codes, and format a fresh ANSI string. Retaining the exact draw and conditional-choice order while withholding visual materialization until either swap fires removes that allocation and render-preparation class from no-swap visits; the remaining floor still samples each visible character as required for deterministic RNG behavior, but rebuilds visuals only for real swaps and the separate rain-state transitions. A fixed-seed virtual-clock Matrix frame-dump comparison across default, elevated-swap, dynamic/always, and xterm configurations, paired with an allocation and CPU profile on a large fixed canvas, is the falsifying proof target: any byte/RNG divergence or failure to reduce `set_appearance`/visual-construction allocation and per-frame CPU materially rejects the move.
Change to test: In `RainColumn::tick`, preserve the current RNG sequence—symbol probability and conditional choice before color probability and conditional choice—but keep replacements optional and call `set_appearance` only when at least one swap succeeds; fetch the unchanged symbol or foreground color only for that update and leave the existing new-head, fade, and visibility updates intact.
Where it lives
perfloop/ttfx · src/effects/matrix.rs
Evidence
Matrix 120x40 virtual-clock CLI across swap and color modes · 10 sample pairs
| metric | baseline | candidate | paired median change | confidence range | required | result |
|---|---|---|---|---|---|---|
default_ns_per_frame |
1237439 |
151973 |
−87.6% (−1083831) |
−1172487 to −1045566 |
< −100000 |
PASSED |
elevated_ns_per_frame |
1337917 |
509237 |
−62.3% (−833246) |
−904438 to −703918 |
≤ 100000 |
PASSED |
always_swap_ns_per_frame |
1311643 |
1343815 |
+2.5% (+32288) |
−32449 to +68788 |
≤ 100000 |
PASSED |
dynamic_ns_per_frame |
1223074 |
132613 |
−88.9% (−1087856) |
−1180549 to −1065752 |
≤ 100000 |
PASSED |
always_ns_per_frame |
1283649 |
131883 |
−89.8% (−1152791) |
−1377994 to −1070509 |
≤ 100000 |
PASSED |
xterm_ns_per_frame |
7111495 |
237040 |
−96.3% (−6848109) |
−6969413 to −6377287 |
≤ 100000 |
PASSED |
allocator_calls_per_frame |
28347 |
605.1 |
−97.9% (−27742) |
−27742 to −27742 |
< −1000 |
PASSED |
Checks: 3 of 3 passed. Verification: no defect found.
Timeline
2026-08-10· Case opened2026-08-12· Case closed