perf: lazy SpecInfo JSON, SkipMetadataCollection, and hot-path allocation cuts#588
Merged
Conversation
…tion cuts Build SpecInfo's JSON representation lazily via new GetSpecJSON/GetSpecJSONBytes/GetSpecJSONError accessors (deprecating direct field access), with parse-time structural validation (duplicate key detection, JSON syntax checks) preserved without the full eager conversion. Add DocumentConfiguration.SkipMetadataCollection to skip collecting diagnostic index metadata (descriptions, summaries, enums, security requirement refs, inline schema Paths), cutting allocations and retained memory on large documents; propagated through v2/v3 document creation. Reduce hot-path overhead: build oneOf/anyOf/allOf/prefixItems schema proxies inline instead of goroutine-per-item, make SchemaProxy's lock a value mutex, scan extensions directly instead of via FindExtensionNodes, and avoid strings.ToLower allocation for already-lowercase keys in BuildModel. Includes golden/parity tests for component ID generation, inline ref collection, lazy JSON behavior, duplicate key detection, and metadata skipping.
This comment has been minimized.
This comment has been minimized.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #588 +/- ##
==========================================
+ Coverage 99.72% 99.74% +0.01%
==========================================
Files 280 280
Lines 33894 33977 +83
==========================================
+ Hits 33802 33891 +89
+ Misses 55 52 -3
+ Partials 37 34 -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:
|
Replace the read-lock/build/upgrade dance in SpecIndex.GetNodeMap with a single exclusive lock, removing the double-checked rebuild path so concurrent callers never build the legacy map twice. Also add a nil-receiver test for SchemaProxy.Schema().
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.
Build SpecInfo's JSON representation lazily via new GetSpecJSON/GetSpecJSONBytes/GetSpecJSONError accessors (deprecating direct field access), with parse-time structural validation (duplicate key detection, JSON syntax checks) preserved without the full eager conversion.
Add DocumentConfiguration.SkipMetadataCollection to skip collecting diagnostic index metadata (descriptions, summaries, enums, security requirement refs, inline schema Paths), cutting allocations and retained memory on large documents; propagated through v2/v3 document creation.
Reduce hot-path overhead: build oneOf/anyOf/allOf/prefixItems schema proxies inline instead of goroutine-per-item, make SchemaProxy's lock a value mutex, scan extensions directly instead of via FindExtensionNodes, and avoid strings.ToLower allocation for already-lowercase keys in BuildModel.
Includes golden/parity tests for component ID generation, inline ref collection, lazy JSON behavior, duplicate key detection, and metadata skipping.
A profiling-driven pass over the parse and index pipeline. Output — refs, definitions,
paths, hashes — is byte-identical to v0.37, enforced by checked-in golden fixtures.
high-level model builds up to 58% faster. Downstream linting retains 21-26% less heap.
SpecInfo.SpecJSON/SpecJSONBytesare now built on first use viathe new
GetSpecJSON(),GetSpecJSONBytes()andGetSpecJSONError()accessors. Thefields remain but are deprecated and nil until an accessor runs — migrate direct reads.
SkipMetadataCollectionconfig flag: skips descriptions, summaries, enums andinline-schema path strings for model-only consumers. Worth ~11% time and 32MB on
stripe-sized documents. Unsafe for diagnostic/rule tooling — linters must not enable it.
title: !!int nope) no longerfail
ExtractSpecInfo— they surface fromGetSpecJSONError(). Duplicate-key errors areunchanged and still fail eagerly, now reported once per definition.
partially-built map reads),
GetNodewaits for completion instead of returning early,and
Release()no longer races concurrent readers.If you read
SpecJSONorSpecJSONBytesdirectly, switch to the accessors — your codestill compiles but will see nil. A version-agnostic pattern: assert the accessor interface
at runtime and fall back to the fields, so one build works against old and new libopenapi.