Repository navigation
Conversation
Reserve the encoded size for string-only requests and format lengths with a stack buffer. Preserve custom key call counts and the collision-safe key encoding. Add encoding regressions and allocation benchmarks. Verified with go vet ./... and go test -race ./... on this branch.
|
Thanks for the analysis and the benchmarks, the allocation numbers reproduced here as well. This has been addressed in e9a3bad with a slightly different approach: Closing this PR in favor of that commit. Thanks again! |
GetCacheKeyrepeatedly grows a zero-capacity builder while writing type- and length-prefixed fields. Long field lengths also allocate throughstrconv.Itoa. This change reserves the exact encoded size for all-string requests and appends lengths through a stack buffer.The existing key encoding, type namespaces, and single invocation of each custom
CacheableParam.GetCacheKey()are preserved. Mixed arguments keep the generic path. There are no public API or dependency changes.Validation
go vet ./...go test -race ./...with this patch applied independentlyEngine-only benchmarks on Apple M4, macOS arm64, Go 1.26.2, using identical workloads on base
c92cc6aand the candidate. Five samples,-benchtime=500ms -count=5 -cpu=10; figures are medians:The warm decision-cache latency change is not statistically significant in this sample (
p=0.151); its allocation reduction is the supported result. These microbenchmarks do not measure end-to-end gateway latency.Reproduce with the added benchmarks on both revisions: