Repository navigation
[Go] Generate zero-copy byte accessors for flyweight var data - #1134
Merged
vyazelenko merged 2 commits intoOct 19, 2026
Merged
Conversation
<Name>Bytes() returns the data as a slice of the message buffer, so a decoder can read var data without allocating or copying.
… as strings or bytes.
This was referenced Oct 12, 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.
Flyweight var data can be read only as a new
string(<Name>(),Get<Name>AsString()), which allocates, or copied into a caller's buffer (Get<Name>(dst)). This adds<Name>Bytes() []byte, which returns the data as a slice of the message buffer, capacity capped at its length, and moves past it like the other getters. The slice is valid only while the buffer holds the message, as the generated comment says. A field added in a later version returnsnilfor an older message.It also adds
BenchmarkEncodeCar,BenchmarkDecodeCarandBenchmarkDecodeCarBytesto the flyweight baseline package; the decode benchmarks read every field of the Car, groups included, with the four var data fields read as strings or as bytes. Linux arm64 (Azure Cobalt 100), Go 1.27, alternating, 10 runs each:BenchmarkDecodeCar(var data as strings)BenchmarkDecodeCarBytes(var data as bytes)Reading a single 52-byte var data field of an Aeron Archive
ReplayRequest:<Name>()34.88 ns and 1 allocation,Get<Name>(dst)13.88 ns,<Name>Bytes()11.64 ns and no allocation.Verified:
./gradlew generateGolangCodecs && cd gocode && make→ all Go tests pass, including the newTestVarDataBytes(values, aliasing of the message buffer, capped capacity, no allocations); a schema withsinceVersion="1"var data returns the value at version 1 andnilat version 0; checkstyle clean.