Skip to content

Extra array copy in Metadata #2167

Open
@carl-mastrangelo

Description

@carl-mastrangelo

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions