Skip to content

perf(compile): reuse rule results on warm and one-edit compiles - #915

Merged
kvlonge merged 5 commits into
mainfrom
perf/chi-441-warm-edit-compile
Oct 2, 2026
Merged

kvlonge merged 5 commits into
mainfrom
perf/chi-441-warm-edit-compile

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

Why

Warm and one-edit compiles re-evaluated every custom rule and the whole built-in rules request even when nothing they depend on had changed, and serialised project facts twice (CHI-441 phase 1: CHI-443, CHI-444, CHI-445, part of CHI-442).

Changes

  • Custom-rule results are reused per subject when every fact the rule read is unchanged. Reads are recorded in the rule host. Filesystem reads are verified against the values the rule actually saw. Untracked rules are keyed on their recorded reads plus all project facts. Rules touching private or unknown attributes are never cached.
  • The built-in rules response is reused for a byte-identical native request.
  • Project facts are built once for built-in and custom rules.
  • Macro context injection is resolved once per loaded macro.
  • New cache keys include the installed code and native build identity.
  • New dense 3k/5k guards: warm and one-edit compiles must match a cold uncached compile (fingerprints), fully reuse the cache when warm, and re-evaluate exactly 3 rules after an edit.

Verification

  • Same-machine medians (CPU s, base → head): 3k warm 12.2 → 10.2, 3k edit 17.7 → 11.9, 5k warm 20.8 → 16.7, 5k edit 27.9 → 19.3; cold unchanged; warm memory down about a third. Output identical in every scenario.
  • Invalidation tests per input kind, including a file edited during evaluation and a native build change.
  • One independent review plus a follow-up; make test, make check-ci.

…e unchanged

The isolated custom-rule host now records which compiler facts each rule
invocation reads through its context. Results are cached per rule and subject
and reused only while every recorded fact digest, the rule implementation and
import closure, the rules configuration, the installed code identity, and the
dialect are unchanged. Rules whose reachable module state changes between
invocations, or that touch private view state, are treated as reading every
fact.

Custom rules no longer serialise the whole compiled project for a cache key:
the project is pickled only when a host run is needed, and built-in rules key
their project-level identity on request facts instead of walking project files.

Refs CHI-443, CHI-444
…ive request

Warm compiles re-sent an unchanged 60 MB request to the native engine,
which spent about a second re-validating per-model cache entries. The
complete response is now memoized under a digest of the serialized request
and the installed code identity, so any fact, scope, config or code change
re-evaluates through the native per-model cache.

Refs CHI-445
Every macro call rebuilt the callable's inspect signature to decide whether
to inject the macro context. The decision is now a cached property of the
loaded macro, removing about 3,600 signature constructions from a dense
3,000-model compile.

Refs CHI-442
Adds 3,000- and 5,000-model dense guards that compile cold, warm, and after
a single model edit, then compare the edit with a from-scratch uncached
oracle. They assert exact fingerprints, complete warm cache reuse, and that
the edit re-evaluates only the edited model's built-in rules while the
project-wide custom rule is reused. The dense job timeout grows to cover the
extra compiles.

Refs CHI-441
…custom-rule results

- Record the digest of each project-tree value a rule actually read in the
  host and refuse to store a result whose filesystem facts changed before
  the parent recorded the fingerprint.
- Key untracked rules on their recorded reads plus every observable fact,
  so files outside the discovered tree (hidden directories) still
  invalidate them.
- Never cache rules that touch private or unknown fact-view attributes.
- Include the thread id in the custom-rule cache temporary file name.
@kvlonge
kvlonge enabled auto-merge (squash) October 2, 2026 23:02
@kvlonge
kvlonge merged commit 01a2bbd into main Oct 2, 2026
34 checks passed
@kvlonge
kvlonge deleted the perf/chi-441-warm-edit-compile branch October 2, 2026 23:25
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