Skip to content

render-pipeline: guard that adapt stays linear — recovers the two timing tests #627's revert took with it - #765

Merged
d-q222 merged 1 commit into
mainfrom
agent/daniel-parent/adapt-linear-guard
Sep 16, 2026
Merged

d-q222 merged 1 commit into
mainfrom
agent/daniel-parent/adapt-linear-guard

Conversation

@d-q222

@d-q222 d-q222 commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

What

Adds crates/render-pipeline/tests/adapt_linear_time.rs — two complexity guards
that keep adapter::adapt linear in the number of \items and open
environments. Test-only; no product code changes.

Why

These two tests existed briefly and were lost, and the thing they guard is the
headline fix of an already-merged PR.

The test file also records the six fuzz-found hang cases from #627's mutation
fuzzer ("hang in render") with their before/after release timings, so that
finding lives in the repo instead of in the commit message of a reverted commit
on an unpushed local branch:

case before #623 after #623
mutated enumitem worksheet 37.5 s 0.29 s
page-builder enlarge-00 21.5 s 0.19 s
715-page list of 20 000 items 23.3 s 0.13 s
1 000 nested itemize 23.8 s 0.15 s
5 000-paragraph article, a center each 8.0 s 1.1 s
300 items inside 1 000 open centers 7.4 s 25 ms (identical PDF bytes)

The thresholds are 10 s against a current cost of 0.08 s — orders of magnitude
of headroom, so these stay quiet on a loaded shared machine and only fire on a
genuine complexity regression.

Overlap check

Test results

cargo test --test adapt_linear_time --no-run on this branch (main 9c5b028d),
run as a separate step so a non-compiling target cannot be counted as green:

Finished `test` profile [unoptimized + debuginfo] target(s) in 10.07s
  Executable tests/adapt_linear_time.rs

cargo test --test adapt_linear_time on this branch:

running 2 tests
test list_items_inside_many_open_environments_are_adapted_in_linear_time ... ok
test a_long_list_is_adapted_without_rescanning_the_source_per_item ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.08s

The same file applied to pre-#623 main (108b2a29, i.e. bbc9583c^), to show
the guards actually bite on the regression they name:

thread 'a_long_list_is_adapted_without_rescanning_the_source_per_item' panicked at tests/adapt_linear_time.rs:62:5:
10 000 list items took 17.570090167s to adapt

thread 'list_items_inside_many_open_environments_are_adapted_in_linear_time' panicked at tests/adapt_linear_time.rs:78:5:
took 17.506552417s to adapt

test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 35.12s

17.5 s before, 0.08 s after, threshold 10 s.

Not done

🤖 Generated with Claude Code

https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz

… environments

What changed:
- Adds crates/render-pipeline/tests/adapt_linear_time.rs with the two
  complexity guards that were lost when #627 reverted 71d8fbf. That
  revert was deduplication, not a defect: #623 fixed the same quadratic
  adapt with a SourceIndex and landed on main as bbc9583, so #627 gave
  the adapter back to #623 — but it took these two tests with it, and
  #623 shipped only source_index_matches_prefix_scans, which checks
  identity, not cost. Nothing on main noticed if adapt went quadratic
  again while still producing the right output.
- The file also records the six fuzz-found hang cases (PR #627's
  mutation fuzzer, "hang in render") with their before/after release
  timings, so the finding lives in the repo rather than in the message
  of a reverted commit on an unpushed branch.
- Test-only. No product code changes.

What was run:
- cargo test --test adapt_linear_time --no-run (main, 9c5b028):
  Finished `test` profile [unoptimized + debuginfo] target(s) in 10.07s
- cargo test --test adapt_linear_time (main, 9c5b028):
  test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.08s
- the same file against pre-#623 main (108b2a2, bbc9583^):
  test result: FAILED. 0 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out; finished in 35.12s
  10 000 list items took 17.570090167s to adapt
  took 17.506552417s to adapt
  so the guards bite on the regression they name: 17.5 s before, 0.08 s
  after, against a 10 s threshold.

Next step: none; #627 carries the fuzzer itself.

Implementation-Agent: claude-opus-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
@d-q222
d-q222 merged commit 0c4a6bf into main Sep 16, 2026
40 of 43 checks passed
ItsAkilesh pushed a commit to ItsAkilesh/flashtex that referenced this pull request Sep 18, 2026
…(#GH-FLAKY-TABLE-LENGTHS-LINEAR)

What changed:
`adapter::tests::table_lengths_scale_linearly_with_the_number_of_tables`
asserted `t800 < t200 * 8`, a ratio over a sub-millisecond baseline (~587us
on PR flash-tex#765 CI). Scheduler noise of a few hundred microseconds is a large
fraction of that baseline, and a ratio's error bars scale with the smaller
operand, so it amplified the noise into an occasional false failure
("800 tables took 5.044542ms, 200 took 587.834us: not linear", which
passed on an unmodified re-run at the same commit).

Replaced the ratio with an absolute ceiling (300ms on t800), the same
pattern as crates/render-pipeline/tests/adapt_linear_time.rs (flash-tex#765).
Measured on dev hardware: normal 800-table runs (best of 5) take
~1-1.3ms in --release, ~10-11ms unoptimized. Forcing
`length_at_checked` to always fall through to `length_at_scan` (i.e.
reverting flash-tex#623 so every table rescans the source instead of using the
per-document index) makes 800 tables take ~1.4s in --release - about a
thousandfold jump. 300ms sits ~250-300x above the normal case and ~5x
below the reintroduced-quadratic case.

What was run:
- `cargo test --no-run` (separate step) before counting any results: compiled clean.
- Before (already established on PR flash-tex#765, not reproduced here): CI failure
  "800 tables took 5.044542ms, 200 took 587.834us: not linear", the same
  commit re-run went green with no change.
- After, single run (--release): `table lengths: 200 tables 308.875us,
  400 tables 603.834us, 800 tables 1.200166ms` / `test ... ok`.
- 30x loop (--release): 30/30 `test result: ok`, t800 ranged
  1.162084ms-1.252833ms, all far under the 300ms ceiling.
- Negative control: temporarily forced `length_at_checked` to always call
  `length_at_scan` (reverting flash-tex#623) and rebuilt. The fixed test failed:
  "800 tables took 1.391193958s (200 took 34.739917ms, 400 took
  207.798417ms): quadratic regression suspected, see flash-tex#623" /
  `test result: FAILED. 0 passed; 1 failed`. Reverted the temporary change
  immediately after (git diff confirmed clean before committing).
- Full `adapter::tests::` module (--release): `test result: ok. 38 passed;
  0 failed; 1 ignored`.

Next step: open PR to main; no further code changes anticipated for this task.

Implementation-Agent: claude-sonnet-5 subagent of daniel-parent
Commit-Executor: daniel-parent subagent
Claude-Session: https://claude.ai/code/session_012c9XLkHjePPGBuarrmE2mz
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