grpc / grpc/grpc-java

Cache higher order objects in HPACK's dynamic table.

Aperta
#2,257 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
netty
Lingua principale
Java
Stelle
12.1k
Fork
4k
Merge medio
2g 17h
PR unite (30g)
37

Descrizione

In #2217, @carl-mastrangelo had the idea to cache high order objects in HPACK's dynamic table. Carl mentioned the example of instead of parsing a jwt token on every request, we could cache an object that already contains the parsed representation, reducing garbage creation and parsing overhead.

Additionally, since Metadata uses String for names, we could for header names cache the String representation.

This would mostly require changes to Netty's HPACK implementation. We need some way to attach additional headers. I suggested to modify the `StaticTable`, `Decoder` and `HuffmanDecoder` to take a `HeaderLiteralFactory` as an optional ctor argument.

``` java
interface HeaderLiteralFactory {
CharSequence newKey(byte[] bytes);
CharSequence newValue(CharSequence key, byte[] bytes);
}
```

Netty's default implementation would simply return `AsciiString` objects. The gRPC implementation, could use String objects for keys. For values, we could special case certain header names and return holder objects e.g.

``` java
class JwtHolder implements CharSequence {
JwtObject jwt;
byte[] bytes;
}
```

Risks
The decoder has no power over what gets cached and what doesn't - it's up to the encoder. We might introduce overhead for headers that don't get cached. Also, a (name, value) is treated as one header entry in HPACK's dynamic table. Say if a users use custom headers, with lots of different values, then caching in the dynamic table might not be very effective, as entries might get evicted before they can be reused (if ever).

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start by reading Netty's HPACK StaticTable, Decoder, and HuffmanDecoder implementations and the related grpc-java integration from issue #2217. Determine how an optional HeaderLiteralFactory could attach reusable key and value objects while preserving HPACK behavior and assess the stated eviction and allocation risks. Done means a settled design with implementation scope and validation tests identified.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
backend-api-design, networking, performance
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.