Repository navigation
Conversation
Each shape's schema was an un-memoized Eval chain, so every reference to a shape re-ran the whole computation of its target. In models where shapes are referenced from several places, this made loading exponential in the depth of the sharing. Schemas are now computed once per shape and shared. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kubukoz
marked this pull request as ready for review
November 18, 2026 11:43
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DynamicSchemaIndex.loadcompiles each shape into anEval[Schema], but these weren't memoized: each entry inschemaMapwas alSchema.map(...)chain, and references to other shapes went throughEval.defer(schemaMap(id)). So every reference to a shape re-ran the whole computation of its target, all the way down (only recursive shapes cut this, thanks to theirEval.later).In models where shapes are referenced from multiple places, this is exponential in the depth of the sharing. For a chain of structures
S0 { a: S1, b: S1 },S1 { a: S2, b: S2 }, ..., load time doubled with each extra level:Fix
.memoizethe schema stored for each shape, so it's computed once and shared by all the shapes referencing it. This only adds caching; the evaluation order is unchanged, so recursive shapes still go through the lazyrecursive(...)schema as before. Everything is still forced duringloadon a single thread.Real-world numbers
On a large production model (~235k shapes in the Smithy model, ~25k schemas and ~640 services in the resulting index), warm runs of
DynamicSchemaIndex.load:applySchemaRefinements = trueTests
SchemaSharingSpecchecks, by reference equality, that schemas of shapes referenced from several places are shared (fails without the fix), plus a depth-40 diamond chain as a backstop against the exponential behaviour (would hang without the fix).🤖 Generated with Claude Code