Skip to content

perf(grpc-js): avoid array allocation for single-value metadata headers - #3099

Merged
murgatroid99 merged 1 commit into
grpc:masterfrom
olavloite:avoid-array-allocation-for-headers
Sep 24, 2026
Merged

murgatroid99 merged 1 commit into
grpc:masterfrom
olavloite:avoid-array-allocation-for-headers

Conversation

@olavloite

Copy link
Copy Markdown
Contributor

Most gRPC metadata headers contain only a single value (such as authorization tokens, tracing headers, and request IDs). Previously, toHttp2Headers always called .map(), allocating a temporary array for every header key on every RPC.

For single-value headers, we now assign the formatted value directly to the header object instead of wrapping it in an array. This eliminates unnecessary allocations and reduces garbage collection pressure on the RPC hot path.

Most gRPC metadata headers contain only a single value (such as authorization
tokens, tracing headers, and request IDs). Previously, `toHttp2Headers` always
called `.map()`, allocating a temporary array for every header key on every RPC.

For single-value headers, we now assign the formatted value directly to the
header object instead of wrapping it in an array. This eliminates unnecessary
allocations and reduces garbage collection pressure on the RPC hot path.
@murgatroid99
murgatroid99 merged commit 4b0c419 into grpc:master Sep 24, 2026
9 of 10 checks passed
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.

3 participants