Skip to content

perf(compile): plan SQL tests in the background in every mode - #926

Merged
kvlonge merged 3 commits into
mainfrom
perf/sql-test-planning
Oct 3, 2026
Merged

kvlonge merged 3 commits into
mainfrom
perf/sql-test-planning

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Why

SQL-test planning is the largest single CPU cost of a cold compile (6.7 s at dense 3k, 23.6 s at 10k). It ran in the background only for --no-cache compiles with rules selected and 128–5,000 models. With the cache on, above 5,000 models, or without rules, it ran inline on the critical path, so a cold compile with the cache was slower than --no-cache (CHI-441 phase 2, CHI-447).

Changes

  • Plan SQL tests on a background thread in every compile mode; the write phase picks up the result where it used to plan inline, so errors and partial writes are unchanged.
  • Collect relation markers natively with a streaming collector instead of converting each parsed test to JSON and walking it.

Verification

  • Same-machine medians (base → head): dense 3k cold with cache 22.8 → 16.7 s wall (34.2 → 30.7 s CPU); dense 10k cold 95.5 → 87.8 s CPU; native planning CPU 3k 6.7 → 4.2 s, 10k 23.6 → 14.8 s. Peak RSS at 10k 3.1 GB. Fingerprints and outputs identical.
  • Integration tests: background planning output equals inline across cache, warm, >5k, no-rules and staged modes; errors from the planning thread match inline. Rust marker-order tests plus a JSON-walk oracle.
  • One independent review; make test, make check-ci.

Native SQL-test planning serialized each parsed model statement to a
serde_json Value only to find its FROM and JOIN marker calls. A streaming
serializer now reproduces that walk, including key order, repeated-key
replacement and to_value failures, cutting native planning CPU by about
40 percent. A JSON-walk oracle in the tests pins the equivalence.
SQL-test planning only ran in the background for uncached projects of
128 to 5000 models with rules selected, so cache-on and large compiles
planned on the critical path in the write phase. Prepared artifacts now
fall back to planning SQL tests alone in the background, against the
published target and its artifact cache, and the write phase consumes
that plan at the point it would otherwise plan inline. Results and
errors are identical to inline planning.
@kvlonge
kvlonge enabled auto-merge (squash) October 3, 2026 23:00
@kvlonge
kvlonge merged commit 9f94ebd into main Oct 3, 2026
34 checks passed
@kvlonge
kvlonge deleted the perf/sql-test-planning branch October 3, 2026 23:18
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