Skip to content

perf(tla): memoize the interpreted-path action text splitters - #191

Merged
zoratu merged 1 commit into
mainfrom
perf/cache-interp-text-splitters
Jul 20, 2026
Merged

perf(tla): memoize the interpreted-path action text splitters#191
zoratu merged 1 commit into
mainfrom
perf/cache-interp-text-splitters

Conversation

@zoratu

@zoratu zoratu commented Jul 20, 2026

Copy link
Copy Markdown
Owner

split_action_body_clauses and split_action_body_disjuncts (action_ir.rs) are pure functions of their input text (the v2 layout-aware parse is deterministic; v2_enabled() is fixed per process), but they're re-invoked on the same action/clause text on every next_states call. During full-space exploration — and especially trace reconstruction, which re-explores the whole graph — re-running the Pratt parse + string scans per visit dominated the hot path for fairness/reconstruction specs once #189 removed the compiled-IR recompilation (gdb showed split_action_body_clauses / split_top_level / matches_keyword_at).

Wrap each splitter as an _uncached inner fn behind a thread-local memoization keyed by the input string (returns a cheap Vec<String> clone instead of re-parsing). Thread-local, so no cross-worker contention.

Result

ACP_NB_WRONG_TLC completes in ~29s (was ~143s post-#189 — a ~5x speedup), same verdict (AC1 violated).

Validation

  • scripts/diff_tlc.sh: 20/20.
  • cargo test --release: 1486 passed / 0 failed.
  • Pure memoization of deterministic functions — no behavior change (confirmed by the gate).

Follow-up to #189 (which cached the compiled action IR in the guard path); together they remove the two dominant per-next_states re-work costs (recompilation + re-splitting).

`split_action_body_clauses` and `split_action_body_disjuncts` (action_ir.rs)
are pure functions of their input text — the v2 layout-aware parse is
deterministic and `v2_enabled()` is fixed per process — but they are
re-invoked on the SAME action/clause text on every `next_states` call. During
full-space exploration, and especially trace reconstruction (which
re-explores the whole graph), re-running the Pratt parse + string scans per
visit dominated the hot path for fairness/reconstruction specs once #189
removed the compiled-IR recompilation (gdb showed
`split_action_body_clauses`/`split_top_level`/`matches_keyword_at`).

Wrap each splitter as an `_uncached` inner fn behind a thread-local
memoization keyed by the input string (returns a cheap `Vec<String>` clone
instead of re-parsing). Thread-local, so no cross-worker contention.

Result: ACP_NB_WRONG_TLC completes in ~29s (was ~143s post-#189, ~5x), same
verdict (AC1 violated). Gate: diff_tlc 20/20, cargo test --release 1486
passed / 0 failed — pure memoization, no behavior change.
@zoratu
zoratu merged commit 54fc7c3 into main Jul 20, 2026
6 checks passed
@zoratu
zoratu deleted the perf/cache-interp-text-splitters branch July 20, 2026 07:30
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