Repository navigation
perf(schema): compile JSON schema once in Validate - #6508
Merged
Merged
Conversation
…ma-cache # Conflicts: # go/internal/osvutil/schema/schema.go # go/internal/osvutil/schema/schema_test.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #6508 +/- ##
==========================================
+ Coverage 58.61% 58.66% +0.04%
==========================================
Files 228 228
Lines 24740 24742 +2
==========================================
+ Hits 14502 14515 +13
+ Misses 10235 10224 -11
Partials 3 3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
michaelkedar
approved these changes
Dec 4, 2026
| } | ||
| } | ||
|
|
||
| func TestValidate_Concurrent(t *testing.T) { |
Member
There was a problem hiding this comment.
This is a little weird in that it doesn't really test that the schema is only being compiled once, but whatever
Contributor
There was a problem hiding this comment.
Just remove the test probably.
another-rex
approved these changes
Dec 4, 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.
Overview
Precompiles the embedded OSV JSON schema once via
sync.OnceValuesingo/internal/osvutil/schema/schema.goinstead of recompilingschema_generated.jsonon everyValidatecall (mirroringossf/osv-schema#691).(This PR was authored with AI assistance.)
Details
compiledSchemausingsync.OnceValuesto lazily compileschemaBytesinto a reusable*gojsonschema.Schemaonce per process.Validate(data []byte)to validate against the compiled schema while preserving the existing error wrapping and formatting.TestValidate_Concurrentingo/internal/osvutil/schema/schema_test.goto verify concurrentValidatecalls under the race detector.Testing
cd go && gofmt -s -l ./internal/osvutil/schema/(clean)cd go && go vet ./internal/osvutil/schema/...(clean)cd go && go test -count=1 -race -shuffle=on ./internal/osvutil/...(pass)cd go && go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.14.0 run ./internal/osvutil/schema/...(0 issues.)