grpc / grpc/grpc-java

Extra array copy in Metadata

Open
#2,167 1 comment 1 reaction 0 assignees View on GitHub
performance
Dominant language
Java
Stars
12.1k
Forks
4k
Avg merge
2d 17h
Merged PRs (30d)
37

Description

In `Metadata.storeAdd()`, the code optimistically tries to allocate a single element array under the premise that most headers will only have a single value.

In `DecompressorRegistry`, it tries too to cache the "grpc-accept-encoding" header and builds it ahead of time. In theory, there should only be one such header.

Sadly, `ClientCallImpl.prepareHeaders()` always adds the "identity" codec before adding the raw, cached encodings, which makes the Arraylist in Meta data be too small, and have to reallocate larger, which copies the tiny array. This happens on every single RPC and was noticed during profiling.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.