Skip to content

Tests: the 8 slowest unit tests do the same checks for a fraction of the CPU - #1385

Merged
GLinnik21 merged 5 commits into
mainfrom
lane/slow-tests
Nov 14, 2026
Merged

GLinnik21 merged 5 commits into
mainfrom
lane/slow-tests

Conversation

@GLinnik21

@GLinnik21 GLinnik21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

What

CI's host unit tests (default features) job spends most of its test time in a handful of CPU-bound debug-build tests. Each one below was profiled (sample / per-test --report-time, alone, --test-threads 1) to find where the time goes, and the cost removed without changing what the test asserts. No #[ignore], no deleted or loosened assertion, no Cargo profile touched.

Per-test before/after

Each measured alone with --test-threads 1 on the shared, loaded Mac, before and after from saved binaries run back to back (the screens walks were run twice per side).

test before after where the time went
plx_telemetry queue::tests::at_the_byte_cap_sessions_are_dropped_before_crash_reports 28.4 s 0.08 s searched for the body size 3 bytes at a time, framing a ~100 KB record (JSON + bitwise CRC) ~2700 times
plx_screens detail::identity_tests::no_landing_on_the_related_row_ever_moves_the_card_under_the_focus 23.5 s / 32.6 s 11.6 s / 12.0 s (user CPU of the 3 walks together: 28.4 / 31.4 s -> 14.7 / 14.6 s) 94% of its samples under frame_with were Dispatcher::state_hash, which frame_with runs twice per frame in a debug build
plx_screens search::tests::no_landing_on_a_search_row_... 4.4 s 2.9-3.7 s same
plx_screens home::tests::no_landing_ever_leaves_the_focused_card_outside_the_window 7.0-7.2 s 4.3-7.0 s (noisy; hardly moved) same path, other costs
plx_ui widgets::tab_capsule_motion_tests::the_top_bar_keeps_three_to_one_on_every_glyph_pixel_of_every_hop 12.4 s 3.4 s ink_at re-derived the pill's ink regions for each of ~5000 pixels
plx_ui widgets::tab_capsule_motion_tests::a_label_a_capsule_is_crossing_stays_readable_on_every_glyph_row_not_only_the_centre_one 5.8 s 1.7 s same
plx_appkit player_hud::tests::long_hud_titles_fit_before_every_control_slot 12.7 s 0.25 s the same unpaused title drawn for every focused control and each of 30 pop frames
plx_media player::ass_source::tests::a_backward_seek_after_a_deep_read_keeps_the_events_at_the_target 9.2 s 1.3 s 30 000 pushes, each copying and ranking the 8192-event window

Whole plx_telemetry binary: 58 s in CI -> 2.3 s here. Binaries run 3 at a time, same machine, load varying (before / after): plx_ui 28.7 -> 9.5 s, plx_appkit 26.7 -> 14.4 s, plx_media 36.3 -> 36.2 s (media is gated by other tests; this one fell 9.2 -> 1.3 s).

The property each test keeps, and the mutation that still fails it

Each mutation was applied to production code, the four crates run, and reverted (the tree is clean).

  • byte cap (queue.rs): four crash reports of the largest size that fit plus a newer session; trim must keep the four crashes in FIFO order and drop the session. The size is now derived from the empty record's frame overhead (four base64 chars per three bytes) and two asserts pin it to encode() (four fit, one base64 group more does not), so the records and the asserted result are the same as before. Mutation: rank a session like a crash report in trim -> ["c2","c3","c4","sess"] instead of ["c1".."c4"], test fails.
  • Canon encoder (plx_machine): the hash is FNV-1a over a tag byte and little-endian bytes. u32/u64/f32/str now feed bytes through one index loop with inline(always) rather than for b in v.to_le_bytes() / v.bytes(), whose iterator next is a call per byte in a debug build. The bytes fed are identical. New test canon_is_fnv_1a_over_tagged_little_endian_bytes compares the stream against a byte-at-a-time reference and against a constant recorded from the previous loops (it passed on the old encoder before the rewrite). Mutation: a different prime inside bytes -> that test fails.
  • Dispatcher::frame_with (plx_ui): the debug_assertions check "a prepare pass changed the logical state" hashed before and after step 9. With draw == false (the walk tests) no prepare pass runs, and the only call between the two hashes is rig.opaque_route(bool), handed one bool and nothing of the hashed state, so it compared a state with itself. The hash pair now runs only when will_present && draw, i.e. when the prepare pass runs. The guard is unchanged for those frames. No test grades the guard itself (none existed); this is argued from the code, not demonstrated by a mutation.
  • identity / home / search walks: assertions, seeds (8) and frames (30 000) unchanged; only the per-frame debug hashing got cheaper (the two items above). The walks are still the slowest tests in plx_screens.
  • tab capsule contrast (worst_contrast_2d): grades every glyph pixel of every pill every frame at 3:1, exactly as before; the ink regions are decided once per call (ink_at is by definition pill_ink(..).at(..)) and the last pixel's contrast is reused when its backing and ink arrays are equal. Mutation: never flip to the focus ink inside the focus capsule (pill_ink) -> the_top_bar_keeps_three_to_one_... and a_label_a_capsule_is_crossing_... fail (9 plx_ui tests fail in all).
  • HUD title: per language, slot and kicker the title is drawn once and checked for the ellipsis, x and fitted width; the per-focus, per-pop-frame check of the control rects against right + MD stays exactly as it was. The draw depends on the cell's right edge, the title and the measure, and with paused = false reads no clock, so the repetitions were identical. Mutation: fit the title to width + 60 in draw_player_title_at -> test fails.
  • ASS deep read (ass_source.rs): the regression is that after a deep read a rewind's events are retired before the stale-ahead ones. Reading MAX_EVENTS + 300 events leaves the same full window (latest 8192) as 30 000 did; the test now asserts the window is full, then rewinds to event 100 (more than STALE_AHEAD_MS behind everything held) and the 100 pushes and assertions at the target are unchanged. Mutation: disable the stale-ahead branch of retire_to_fit -> the test fails (and one other media test).

Gates

Run on the committed tree (git status --short empty before and after), via the make test-crate recipe minus its disk-preflight prerequisite (see below):

plx_machine    test result: ok. 118 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.62s
plx_telemetry  test result: ok. 375 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 2.34s
plx_ui         test result: ok. 1627 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 12.74s
plx_appkit     test result: ok. 953 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 27.48s
plx_screens    test result: ok. 2151 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 38.32s
plx_media      test result: ok. 2134 passed; 0 failed; 100 ignored; 0 measured; 0 filtered out; finished in 49.54s
cargo-test-parallel: 6 test binaries, 6 at a time, 50.4s wall (sum of binaries 135.6s)
make check-nodef: Finished `dev` profile [unoptimized + debuginfo] target(s) in 26.50s, exit 0

(The times are 6 binaries at once on a machine at load 10-70.) Full make check was not run (CI gates it). make test-crate's disk-preflight hung for 20+ minutes under load while it ran build-gc.sh --evict on other lanes' trees, so the recipe was run directly with the same arguments; free space was 24 GiB.

The generated-enum certificate (ci/proofs/platform-generated-enums.json, ci/readonly_generated.py) pins machine/src/machine.rs whole-file, so the file's new hash is added to it (the way #1358 and #1366 did): it certifies only the newtype! macro and its ten u32 invocations (lines 62-108), which this PR does not touch (first changed line is 882, inside impl Canon); the declarations the checker extracts are identical before and after.

Not done

  • plxnative_modules (138.8 s in CI) was not profiled.
  • hud_format::lint_tests (still 5.3 / 3.2 / 3.0 / 1.8 s alone for the four slowest) and the other plx_appkit / plx_screens tests under 2 s were not touched.
  • The three no_landing walks are still 12 / 7 / 3 s; shrinking them further means fewer seeds or frames, which needs a mutation set of the focus-stability code that I did not build, so counts are unchanged.
  • testlock::serial() critical sections were not narrowed.

🤖 Generated with Claude Code

GLinnik21 and others added 5 commits November 14, 2026 06:46
at_the_byte_cap_sessions_are_dropped_before_crash_reports found the body size by
growing it three bytes at a time and framing a ~100 KB record (JSON plus a
bitwise CRC) on every step: about 2700 frames, 28 s alone. A frame is a fixed
overhead plus four base64 characters per three bytes, so the body is now
derived from the overhead of an empty record, and two asserts pin the
derivation to encode(): four reports of that size fit, one base64 group more
does not. The records fed to trim() and the asserted result are unchanged;
0.08 s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… for nothing

Most of a dispatcher frame in a test (a debug build) was Dispatcher::state_hash: a sampled
detail::identity_tests walk spent 64% of its CPU in the two state_hash calls that bracket the
prepare pass and 94% under frame_with in all, almost all of it in Canon's per-byte iterator calls.

- Canon feeds bytes through one index loop (`bytes`) and inlines byte/tag, instead of
  `for b in v.to_le_bytes()` / `v.bytes()`, whose iterator `next` is a call in a debug build. The
  bytes fed, and so the hash recorded replay anchors compare against, are unchanged; a new test pins
  the stream against a byte-at-a-time reference and against the value the previous loops produced.
- frame_with hashes before and after the prepare pass only when it runs one. With draw == false (the
  walk tests) the only call between the two hashes is rig.opaque_route(bool), which holds none of the
  hashed state, so the assertion compared a state with itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
a_backward_seek_after_a_deep_read_keeps_the_events_at_the_target pushed 30 000 events and rewound
to event 10 000. Every push past the 8 192-event window copies and ranks the whole window, so 21 800
of those pushes were the same quadratic eviction repeated; the window held the identical latest
8 192 events at the seek after MAX_EVENTS + 300 reads. The test now reads that far, asserts the
window is full, and rewinds to event 100, which is still more than STALE_AHEAD_MS behind everything
held. The 100 pushes at the target and their assertions are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n once

- long_hud_titles_fit_before_every_control_slot drew the same title (an unpaused draw reads no
  clock) for every focused control and every one of 30 pop frames; it now draws it once per
  language, slot and kicker and keeps the per-frame pop check against the control rects.
- worst_contrast_2d re-derived the pill's ink regions for each of ~5 000 pixels
  (`ink_at` is `pill_ink(..).at(..)`); it derives them once and reuses the last pixel's contrast
  when its backing and ink are the same values.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…um certificate

`machine/src/machine.rs` is pinned whole-file in `ci/proofs/platform-generated-enums.json`
and `ci/readonly_generated.py`, so #1385's rewrite of the `Canon` byte loops failed
`check-machine-shape.py` (the machine-shape audit lost its certificate for the newtype id
structs, so every shared opaque payload read as unproven) and `test_readonly_generated.py`.

What the certificate certifies from machine.rs is the `newtype!` macro and its ten `u32`
invocations: `declarations()` lexes exactly those and emits `pub struct Name(pub u32)`.
The PR's change is `impl Canon` and `canon_tests`, from line 882 on; lines 1-881 are
byte-identical, the extracted declarations are identical, and the FNV-1a byte stream is pinned
by the new `canon_is_fnv_1a_over_tagged_little_endian_bytes` test. So the new file hash is
added to `MACHINE_SOURCES`, the certificate is regenerated with `produce_certificate`
(only the machine.rs hash list and one review line change) and `CERTIFICATE_SHA256` is the
hash of that certificate. The way #1358 and #1366 updated it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@GLinnik21
GLinnik21 merged commit 2b76740 into main Nov 14, 2026
22 checks passed
@GLinnik21
GLinnik21 deleted the lane/slow-tests branch November 14, 2026 04:59
GLinnik21 added a commit that referenced this pull request Nov 14, 2026
Brings in #1383 and #1385; nothing in them touches the hostsim suite or
the files this branch edits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant