Repository navigation
Fix numeric precision in schema JSON documents - #742
Closed
maharshi-coding wants to merge 1 commit into
Closed
maharshi-coding wants to merge 1 commit into
maharshi-coding wants to merge 1 commit into
Conversation
Collaborator
|
closing in favor of #745 |
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.
Issue #, if available:
Fixes aws/aws-sdk-go-v2#3614.
Description of changes:
Schema JSON
ReadDocumentbuilds an opaque document throughparser.value(), which converted every numeric token withstrconv.ParseFloat(..., 64). This silently rounds integers above 2^53 and can make a subsequent typedint64document decode fail nearMaxInt64.Keep validated numeric tokens as
encoding/json.Number. The existing document decoder then exposesdocument.Numberor parses the requested concrete numeric type without an intermediate float. The numeric text is copied because documents can outlive the pooled deserializer and its input buffer.Also recognize
json.Numberin the reflection-based document encoder. This keeps numbers numeric when forwarding an opaque document throughWriteDocument, rather than quoting them as strings. It uses the existing JSON number grammar validation; ordinary strings, existingdocument.Numbervalues, and the existing empty-number zero-value behavior are preserved. Typed schema numeric readers and public interfaces are unchanged. No generated SDK files are modified.Validation:
407b01fa), and a local Smithy replacement. No Neptune cluster or AWS credentials were used.9007199254740993re-marshaled as9007199254740992;MaxInt64re-marshaled as9223372036854776000and failed typed decoding. After: both retain every digit, dynamic values aredocument.Number, and typedint64decoding succeeds with no error. All three external HTTP regression tests fail against original Smithy and pass with the fix, including with-race.make unit-racepasses, includinggo vet --alland race tests across the root and four nested runtime modules. The complete root suite passes on the minimum supported Go 1.24.0; the final encoder suite also passes on that toolchain.-raceagainst the local runtime replacement. The affected JSON parser package passes a fresh race run. Changed Go files are formatted.UseNumber; five valid-number JSONTestSuite cases no longer need overflow skips.Performance:
Eight 200ms benchmark samples per case on Go 1.27.3, Darwin/arm64: the six-number document fixture's median changes from 728.4 to 526.1 ns/op, with 680 to 800 B/op and 17 to 22 allocations/op. Keeping owned numeric text costs storage but avoids float parsing. The typed-deserialization benchmark retains 3,824 B/op and 104 allocations/op; its timing variation is not treated as a significant speedup. These are local microbenchmarks, not a general workload guarantee.
This contribution was prepared with AI assistance and independently reviewed through OSS-Agent.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.