Conversation
… string copy
Canonicalize previously wrapped its []byte input as
strings.NewReader(string(data))
The `string([]byte)` conversion is a full copy of the input bytes onto the
heap. For large agent cards / task payloads on a signature hot path,
that's an allocation roughly the size of the canonical input per call.
`bytes.NewReader(data)` provides the same `io.Reader` interface to
`json.NewDecoder` while sharing the caller's existing slice — zero
extra bytes allocated, zero extra copies. The decoded JSON tree (and
therefore the canonical output) is byte-for-byte identical to before
because both readers feed the same bytes into the JSON tokenizer.
All existing TestCanonicalize* cases still pass.
Signed-off-by: Jason Perlow <jperlow@gmail.com>
|
|
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
Canonicalizepreviously wrapped its[]byteinput as`strings.NewReader(string(data))`. The `string([]byte)` conversion
forces a full heap copy of the input bytes before feeding the
json.Decoder. For large agent cards / task payloads on signature hotpaths, that's an allocation roughly the size of the canonical input per
call.
bytes.NewReader(data)exposes the sameio.Readerinterface tojson.NewDecoderwhile sharing the caller's existing slice — zeroextra bytes, zero extra copies. The decoded JSON tree (and therefore
the canonical output) is byte-for-byte identical because both readers
feed the same bytes into the tokenizer.
All existing tests continue to pass.
```
$ go test ./internal/a2a/ -count=1
ok github.com/bubblefish-tech/nexus/internal/a2a 0.250s
```
Signed-off-by: Jason Perlow jperlow@gmail.com