Repository navigation
perf: reuse registry snapshots for independent schema lookups - #131
Merged
jdesrosiers merged 2 commits intoOct 12, 2026
Merged
Conversation
Instead of copying the schema registry into each browser's cache, getSchema passes the registry to the browser as a fallback lookup (@hyperjump/browser 1.6.0). This makes registry lookups O(1) whether or not a browser is passed and removes the snapshot and merge bookkeeping. Browsers now always see the current registry. A schema that is unregistered is no longer found by existing browsers, which keeps them consistent with the dialect being unloaded. Bundling checks the registry as well as the cache when deciding whether a reference is to an embedded resource, since registered schemas are no longer in the cache. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jdesrosiers
approved these changes
Oct 12, 2026
jdesrosiers
left a comment
Collaborator
There was a problem hiding this comment.
I went a slightly different direction. Thanks for bringing it up.
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.
Fixes #130.
Avoid copying the entire schema registry for every independent
getSchema()call by reusing a shared registry snapshot.The snapshot is invalidated whenever a schema is registered or removed. Existing browsers retain their cached schemas, including entries that have since been removed or replaced.
Fetched documents remain local to each browser, and lookups using an existing browser preserve the current merge behavior.
Performance
Benchmarked independent
Registered schemas | Before | After | Speedup -- | -- | -- | -- 100 | 0.0184 ms | 0.0056 ms | 3.3× 1,000 | 0.0971 ms | 0.0043 ms | 22.6× 5,000 | 0.8421 ms | 0.0040 ms | 210.5×getSchema()calls with different registry sizes.The optimization removes the registry-size-dependent overhead from repeated independent lookups when the registry remains unchanged.
The first lookup after a registry change still rebuilds the snapshot.
Testing
Added seven regression tests covering:
Browser cache isolation
Schema removal and replacement
Late schema registration
Externally supplied browsers
Reference resolution
Validation results:
npm test— 14,975 passed, 64 skippednpm run lint— passednpm run check-types— passedAll existing tests pass with the optimization.