Skip to content

Reuse already-compiled schema nodes where context matches - #10

Merged
xinz merged 2 commits into
mainfrom
opti/cc
Sep 9, 2026
Merged

xinz merged 2 commits into
mainfrom
opti/cc

Conversation

@xinz

@xinz xinz commented Sep 9, 2026 •

Copy link
Copy Markdown
Owner

Reuse boundaries

  • A per-invocation index is built from the initial compiled tree, before the root's raw schema is replaced by the containing document. It is skipped when there are no scanned scopes and discarded after compilation.
  • The index visits only compiler-owned schema-bearing rule slots and local definitions, not raw documents or literal enum/const payloads. Keys are resource/anchor identities, not recursively hashed raw schema maps.
  • Scope reuse requires exact raw equality (===), the same effective base, and the same vocabulary as the initial tree. Loader and assertion context are shared within this invocation. Required-vocabulary validation and dialect loader calls still happen before reuse, with their original ordering/errors.
  • Deleting $id can change keyword-map enumeration order. A conservative immediate-key order check rejects reuse in that case, preserving rule and diagnostic order, including finalizers.
  • Explicit refs still use batch_resolve_reduce/4 against the containing document. Only an exact initial direct-def key with matching raw and effective base can be reused. Boolean targets retain their prior compilation path.
  • Existing registry skips, the contextual-root special case, scanner-selected winners, and explicit-ref overwrite precedence remain unchanged. Index collisions may lose a reuse opportunity but cannot override those winners.
  • Newly compiled fallback scopes are not inserted into the frozen initial index. Scanner-only nodes, context mismatches, order-changing maps, and unmatched pointer targets may still recompile. This is not universal linear compilation. No global cache, ETS/process-dictionary state, dependency, or public schema field was added.

Sequential before/after benchmark, median time per compilation:

Workload Before After
Nested resource chain, depth 100 36.64 ms 1.60 ms
Nested resource chain, depth 400 738.14 ms 6.68 ms
Nested $defs resources, depth 100 38.59 ms 1.57 ms
200 direct-definition references 12.77 ms 7.43 ms

@xinz
xinz merged commit 7d103dc into main Sep 9, 2026
1 check passed
@xinz
xinz deleted the opti/cc branch September 9, 2026 16:22
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