Repository navigation
Compile each registry schema once - #541
Merged
Merged
Conversation
`validateAgainstSchema` built a new schema loader and compiled the embedded JSON schema on every call. `ValidateUpstreamRegistryBytes` then compiled the publisher-provided schema again for every server that carries publisher-provided extensions, so validating a registry cost one full compilation per server. Compile each embedded schema on first use and reuse the result. The schemas are embedded, so a compilation result never changes, and `gojsonschema.Schema.Validate` does not modify the schema, so callers can share it concurrently. Validating a 100-server registry drops from 40 ms and 55 MB allocated to 0.9 ms and 1 MB. Co-Authored-By: Claude Opus 5.5 <[email protected]>
rdimitrov
enabled auto-merge (squash)
November 20, 2026 09:17
amirejaz
approved these changes
Nov 20, 2026
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.
Summary
validateAgainstSchemabuilt a new schema loader and compiled the embedded JSON schema on every call.ValidateUpstreamRegistryBytesalso validates each server's publisher-provided extensions separately, so a registry with N servers that carry extensions paid for N+1 full schema compilations.This compiles each embedded schema once, on first use, and reuses it:
gojsonschema.Schema.Validateonly reads the compiled schema, so concurrent callers can use the same one.No exported API changes. The only visible difference: if an embedded schema file couldn't be read, the error now carries the caller's prefix (for example
registry schema validation failed: failed to read embedded schema …). That can't happen with the files that ship.Results
BenchmarkValidateUpstreamRegistryBytes, each server carrying publisher-provided extensions:This matters for toolhive-registry-server, which runs this validation on every file and git sync whose content changed, and on publish.
Testing
-racegive the right results.go test -race ./registry/...passes. golangci-lint reports 0 issues;go vetandtask license-checkpass.🤖 Generated with Claude Code