transport: avoid slice reallocation during header creation #8547
+13
−1
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.
This PR improves the size estimate while pre-allocating
headerFieldsto avoid reallocations, which pprof showed were responsible for ~4% of total memory allocations. This change improves performance, increasing QPS by 1% while reducing bytes/op by 4% and latencies by 0.3-4%.Tested
go run benchmark/benchresult/main.go unary-before unary-after unary-networkMode_Local-bufConn_false-keepalive_false-benchTime_1m0s-trace_false-latency_0s-kbps_0-MTU_0-maxConcurrentCalls_120-reqSiz e_1024B-respSize_1024B-compressor_off-channelz_false-preloader_false-clientReadBufferSize_-1-clientWriteBufferSize_-1-serverReadBuffer Size_-1-serverWriteBufferSize_-1-sleepBetweenRPCs_0s-connections_1-recvBufferPool_simple-sharedWriteBuffer_false Title Before After Percentage TotalOps 6327736 6390728 1.00% SendOps 0 0 NaN% RecvOps 0 0 NaN% Bytes/op 13903.23 13354.55 -3.95% Allocs/op 156.22 155.23 -0.64% ReqT/op 863946888.53 872547396.27 1.00% RespT/op 863946888.53 872547396.27 1.00% 50th-Lat 1.00991ms 1.006914ms -0.30% 90th-Lat 1.678329ms 1.610331ms -4.05% 99th-Lat 2.517556ms 2.497122ms -0.81% Avg-Lat 1.136117ms 1.125311ms -0.95% GoVersion go1.24.4 go1.24.4 GrpcVersion 1.76.0-dev 1.76.0-devRELEASE NOTES: