Skip to content

perf(compile): reuse discovery, analysis and writes after model-only edits - #971

Merged
kvlonge merged 3 commits into
mainfrom
perf/incremental-edit-phases
Oct 6, 2026
Merged

kvlonge merged 3 commits into
mainfrom
perf/incremental-edit-phases

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Why

After a one-model edit, compile still rediscovered every declaration file, re-read every model's analysis from the cache and re-compared every compiled artifact, even when render reuse (#955) had already shown only one model changed (CHI-508).

Changes

  • Discovery: non-model declaration files (sources, tests, macros, schemas) are reused when only existing model files changed; any other change rediscovers everything.
  • Analysis: an unchanged model reuses its stored column analysis only when its render was reused, no other model shares its cache key, its cache key equals the one computed in this compile, and every direct parent's final signature in this compile matches the one recorded with it. Otherwise it takes the normal path. New analysis_reuse_hits counts analyses actually served.
  • Writes: compiled files whose stored stamp and digest match are neither read nor rewritten.
  • Semantic validation still runs in full.

Verification

  • Real-CLI edit-chain oracle against --no-cache, including two-hop SELECT * chains with plan, build, another target or a no-reuse compile between edits, same-SQL twin models, and random chains; each new reuse fails the oracle when deliberately broken.
  • Second edit after cold, alternating medians: dense 3k CPU 8.8 → 8.0 s (analysis ~1150 → ~435 ms), dense 10k and a ~1,400-model project also faster; cold and no-op unchanged.
  • One independent review plus follow-up; make test, make check-ci.

After an edit that touches only existing model files, reuse the non-model declaration files the stored compile parsed (sources, tests, schemas, macros, functions, seeds, scoped declarations) and discover only the model files again. Any other change discovers everything and records the declarations with the stored renders.
After a model-only edit, a model whose render was reused, whose recomputed analysis cache key equals the stored one and is used by no other model, and whose shared analysis inputs are unchanged may take its analysis from the stored compile instead of reading the analysis cache. The served analysis is kept only once its parents are final in this compile and each parent's final output signature equals the signature recorded with it; otherwise the model is analyzed again and its dependents are invalidated as usual. Previous signatures still come from the analysis cache, as without reuse, and an analysis is recorded for the next compile only when its recorded parent signatures match this compile's final ones, so another command advancing the analysis cache between compiles cannot leave a stale analysis served. Published shapes are computed only for models without a declared shape.
Store each compiled artifact's digest beside its stat stamp in the compile reuse entry. When a later full compile writes an artifact whose stat identity still matches the stored stamp and whose new contents have the stored digest, it neither reads nor rewrites the file. Any stat or digest difference falls back to comparing the file's bytes.
@kvlonge
kvlonge enabled auto-merge (squash) October 6, 2026 10:40
@kvlonge
kvlonge merged commit 372e0c1 into main Oct 6, 2026
32 checks passed
@kvlonge
kvlonge deleted the perf/incremental-edit-phases branch October 6, 2026 11:07
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