Extra array copy in Metadata
- Vorherrschende Sprache
- Java
- Sterne
- 12.1k
- Forks
- 4k
- Ø Merge
- 2 T. 17 Std.
- Gemergte PRs (30 T.)
- 37
Beschreibung
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.
Beitragsleitfaden
Rechercherichtung
Start with Metadata.storeAdd(), DecompressorRegistry, and ClientCallImpl.prepareHeaders() to trace how the cached grpc-accept-encoding values and the identity codec are added. Confirm the allocation and copy behavior during RPC header preparation; done means avoiding the unnecessary array reallocation described in the issue without changing the resulting headers.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- grpc, java
- Bereich
- backend-api-design, performance
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100