perf(go): pool the request-path wire payload#3442
Open
matanper wants to merge 8 commits into
Open
Conversation
Cache constant Identifier wire bytes in NewIdentifier; add MarshalledSize and AppendBinary on Identifier and PollMessages so the TCP client can encode the wire payload directly into a pooled buffer (requestBufPool) instead of allocating per RPC. The 8-byte response status header now reads into a stack-local buffer via readInto. Identifier.Value is no longer aliased to the cached encoded bytes, so external mutations to the exported Value field can't corrupt the wire encoding. Coupling tests assert MarshalledSize == len(AppendBinary(nil)) for both types to catch future drift. Benchmarks (foreign/go/benchmarks/poll_encode_benchmark_test.go): PollMessages encode 23.06 ns / 64 B / 1 allocs -> 7.74 ns / 0 B / 0 allocs Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Thanks for the PR. It is labeled Slash commands (own line, regular comment) move it around the queue:
See CONTRIBUTING.md for details. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3442 +/- ##
============================================
+ Coverage 74.30% 74.65% +0.35%
Complexity 943 943
============================================
Files 1245 1228 -17
Lines 121653 120559 -1094
Branches 97959 97263 -696
============================================
- Hits 90390 90004 -386
+ Misses 28307 27619 -688
+ Partials 2956 2936 -20
🚀 New features to boost your workflow:
|
…nd do() Adds unit tests for the new request-path code paths: - encodeWireRequest appender fast path vs MarshalBinary fallback produce byte-identical output to the legacy createPayload pipeline. - encodeWireRequest grows an undersized buffer in both paths. - encodeWireRequest propagates MarshalBinary errors. - acquireRequestBuf / releaseRequestBuf round-trip; oversized buffers are dropped instead of poisoning the pool. - do() end-to-end via net.Pipe: the wire bytes the server reads match cmd.MarshalBinary() and the response is decoded correctly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Renames the four multi-underscore test names to use the existing Test<Symbol>_<Scenario> single-underscore pattern. Factors serverRespond into serverRespondCapture (which returns the request bytes) so the end-to-end Do test can assert on what the server saw without inlining its own goroutine reader. Existing serverRespond callers are unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
hubcio
requested changes
Jun 9, 2026
…headers to IggyTcpClient
…nper/iggy into perf/iggy-tcp-request-alloc
Contributor
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.
Which issue does this PR address?
Closes #3441
Rationale
Reduces per-RPC allocation pressure on the Go client's TCP poll path
What changed?
createPayloadallocates a fresh[]byteper RPCsync.Pool-backed buffer (0 allocs)make([]byte, 8)per RPCrespHeader [8]bytefield onIggyTcpClientPollMessages: body encodeMarshalBinaryallocates the output sliceAppendBinarywrites into the pooled buffer (0 allocs)PollMessages:Identifierwire bytesNewIdentifier; appended from the cacheMarshalBinaryallocates the output sliceMarshalBinaryis still called, output is appended into the pooled bufferIdentifierwire bytesIdentifier.MarshalBinaryIdentifier.MarshalBinarystill allocates per call; the cache is only consumed viaAppendBinary, which onlyPollMessagescalls in this PR. Migrating other commands'MarshalBinaryimplementations toAppendBinarywould unlock this for them too.Local Execution
Passed
AI Usage