Skip to content

perf: reuse registry snapshots for independent schema lookups - #131

Merged
jdesrosiers merged 2 commits into
hyperjump-io:mainfrom
Kaileshwar16:fix/130-schema-registry-lookup
Oct 12, 2026
Merged

jdesrosiers merged 2 commits into
hyperjump-io:mainfrom
Kaileshwar16:fix/130-schema-registry-lookup

Conversation

@Kaileshwar16

Copy link
Copy Markdown
Contributor

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 getSchema() calls with different registry sizes.

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×

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 skipped

  • npm run lint — passed

  • npm run check-types — passed

All existing tests pass with the optimization.

Kaileshwar16 and others added 2 commits October 10, 2026 12:17
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 jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went a slightly different direction. Thanks for bringing it up.

@jdesrosiers
jdesrosiers merged commit 2094bc3 into hyperjump-io:main Oct 12, 2026
2 checks passed
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.

perf: Schema lookup overhead scales with the number of registered schemas

2 participants