Skip to content

Use HPACK spelling for HTTP/2 compression#2271

Open
pavel-ptashyts wants to merge 3 commits into
AsyncHttpClient:mainfrom
maygemdev:perf/http2-accept-encoding-hpack
Open

Use HPACK spelling for HTTP/2 compression#2271
pavel-ptashyts wants to merge 3 commits into
AsyncHttpClient:mainfrom
maygemdev:perf/http2-accept-encoding-hpack

Conversation

@pavel-ptashyts

@pavel-ptashyts pavel-ptashyts commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • rewrite only AHC's generated default Accept-Encoding value from gzip,deflate to gzip, deflate while copying headers into HTTP/2 frames
  • allow HPACK to use static-table entry 16 for the generated value
  • preserve user-supplied Accept-Encoding spelling and leave HTTP/1 output unchanged
  • add HTTP/2 behavioral coverage and a deterministic encoded-size test
  • correct the existing JMH benchmark documentation about its returned value

Performance evidence

With Netty 4.2.15.Final and a fresh HPACK encoder:

  • gzip,deflate: 14 encoded bytes
  • gzip, deflate: 1 encoded byte through the indexed static-table representation

A short JMH validation on JDK 21 with -prof gc measured 1032 B/op for the literal spelling and 680 B/op for the static-table spelling. Timing was noisy, so this PR relies on the deterministic wire-size test rather than claiming a stable CPU improvement.

Validation

  • ./mvnw -pl client -Dtest='org.asynchttpclient.netty.request.AcceptEncodingHpackTest,org.asynchttpclient.BasicHttp2Test#generatedAcceptEncodingUsesHpackStaticValueOverHttp2+userAcceptEncodingSpellingIsPreservedOverHttp2' test (3 tests)
  • AcceptEncodingHpackBenchmark -f 1 -wi 3 -i 5 -w 500ms -r 500ms -prof gc
  • existing full BasicHttp2Test validation from the initial change

Attribution

Codex on behalf of Pavel Ptashyts

pavel-ptashyts and others added 2 commits July 20, 2026 17:06
When compression is enforced, the request factory creates the default
Accept-Encoding value as "gzip,deflate" for HTTP/1 compatibility.
HTTP/2's HPACK static table contains "gzip, deflate", so the H2 frame
writer missed the compact static entry for the generated default.

Rewrite only the generated default while copying headers into HTTP/2
frames. User-supplied Accept-Encoding values keep their original
spelling, and HTTP/1 output remains unchanged.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
Add a deterministic encoder test proving that the HPACK static-table
spelling uses a one-byte indexed representation while the old spelling
requires a literal value.

Clarify that the JMH benchmark reports execution time and allocation;
its return value prevents dead-code elimination but is not a separate
JMH metric.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
@pavel-ptashyts
pavel-ptashyts force-pushed the perf/http2-accept-encoding-hpack branch from 7cb1653 to 44208e5 Compare July 20, 2026 15:08
Replace the remaining non-ASCII punctuation in the touched HPACK
benchmark so the source follows the repository guidelines in AGENTS.md.

Codex on behalf of Pavel Ptashyts

Co-Authored-By: Codex <codex@openai.com>
@pavel-ptashyts
pavel-ptashyts force-pushed the perf/http2-accept-encoding-hpack branch from 44208e5 to 527368f Compare July 20, 2026 15:45
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.

1 participant