You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
transport: Replace closures with interfaces to avoid heap allocations (#8630)
In Go, creating a closure results in a heap allocation if the compiler
determines the closure might outlive the function in which it was
created. This change removes two such closures, replacing them with
interfaces that are implemented by the `ClientStream` and `ServerStream`
structs.
While this pattern may slightly reduce readability, the performance
benefit is worthwhile, as this transport code is executed for every new
stream. This reduces allocs/unary RPC by 2.5%.
## Testing
```sh
# test command
go run benchmark/benchmain/main.go -benchtime=60s -workloads=unary \
-compression=off -maxConcurrentCalls=500 -trace=off \
-reqSizeBytes=100 -respSizeBytes=100 -networkMode=Local -resultFile="${RUN_NAME}" -recvBufferPool=simple
# results
go run benchmark/benchresult/main.go unary-before unary-after
Title Before After Percentage
TotalOps 7593738 7708364 1.51%
SendOps 0 0 NaN%
RecvOps 0 0 NaN%
Bytes/op 10218.45 10185.84 -0.32%
Allocs/op 164.85 160.84 -2.43%
ReqT/op 101249840.00 102778186.67 1.51%
RespT/op 101249840.00 102778186.67 1.51%
50th-Lat 3.617561ms 3.568623ms -1.35%
90th-Lat 5.218682ms 5.131828ms -1.66%
99th-Lat 6.052632ms 5.950261ms -1.69%
Avg-Lat 3.948414ms 3.889006ms -1.50%
GoVersion go1.24.4 go1.24.4
GrpcVersion 1.77.0-dev 1.77.0-dev
```
RELEASE NOTES: N/A
0 commit comments