Skip to content

Conversation

@yeya24
Copy link

@yeya24 yeya24 commented Oct 23, 2025

Summary

metadata.FromIncomingContext will copy all metadata headers which has additional allocations. while metadata. ValueFromIncomingContext only copies the specific metadata header it asks for. When there are multiple headers in the metadata, copying everything can add quite a lot of allocations of small objects under high TPS, causing addtional load to GC

Tests

Benchmark.

benchstat results/BenchmarkExtractFromGRPCRequest/1/2025-10-23-T14-51-49.bench.out results/BenchmarkExtractFromGRPCRequest/0/2025-10-23-T14-50-18.bench.out
name                       old time/op    new time/op    delta
ExtractFromGRPCRequest-10    1.20µs ± 2%    0.08µs ± 5%   ~     (p=0.100 n=3+3)

name                       old alloc/op   new alloc/op   delta
ExtractFromGRPCRequest-10    1.80kB ± 0%    0.08kB ± 0%   ~     (p=0.100 n=3+3)

name                       old allocs/op  new allocs/op  delta
ExtractFromGRPCRequest-10      21.0 ± 0%       3.0 ± 0%   ~     (p=0.100 n=3+3)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant