Skip to content

Improve HPACKEncoding performance by ~2x#541

Merged
fabianfett merged 1 commit into
mainfrom
ff-make-hpack-encoding-2x-faster
Mar 10, 2026
Merged

Improve HPACKEncoding performance by ~2x#541
fabianfett merged 1 commit into
mainfrom
ff-make-hpack-encoding-2x-faster

Conversation

@fabianfett
Copy link
Copy Markdown
Member

Lets use the benchmark in #540:

main:

HPACKHeaderEncoding_APNS
╒══════════════════════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╕
│ Metric                   │        p0 │       p25 │       p50 │       p75 │       p90 │       p99 │      p100 │   Samples │
╞══════════════════════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╡
│ Instructions (K) *       │        42 │        42 │        42 │        42 │        42 │        42 │        42 │       388 │
├──────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Malloc (total) *         │         0 │         0 │         0 │         0 │         0 │         0 │         0 │       388 │
├──────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Time (wall clock) (ns) * │      2444 │      2519 │      2548 │      2580 │      2613 │      2843 │      4240 │       388 │
╘══════════════════════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╛

this branch:

HPACKHeaderEncoding_APNS
╒══════════════════════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╕
│ Metric                   │        p0 │       p25 │       p50 │       p75 │       p90 │       p99 │      p100 │   Samples │
╞══════════════════════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╡
│ Instructions (K) *       │        26 │        26 │        26 │        26 │        26 │        26 │        26 │      1017 │
├──────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Malloc (total) *         │         0 │         0 │         0 │         0 │         0 │         0 │         0 │      1017 │
├──────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Time (wall clock) (ns) * │       916 │       950 │       961 │       970 │       982 │      1010 │      1050 │      1017 │
╘══════════════════════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╛

@fabianfett fabianfett added the 🔨 semver/patch No public API change. label Mar 10, 2026
@fabianfett fabianfett changed the title Improve HPACKEncoding by ~2x Improve HPACKEncoding performance by ~2x Mar 10, 2026
@fabianfett fabianfett enabled auto-merge (squash) March 10, 2026 16:21
Comment on lines +776 to +778
guard self.utf8.count == to.utf8.count else {
return false
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it make more sense to push this down into the func on the utf8 view?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't ask me why, but this kills performance:

==================
NIOHPACKBenchmarks
==================

HPACKHeaderEncoding_APNS
╒══════════════════════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╤═══════════╕
│ Metric                   │        p0 │       p25 │       p50 │       p75 │       p90 │       p99 │      p100 │   Samples │
╞══════════════════════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╪═══════════╡
│ Instructions (K) *       │        46 │        46 │        46 │        46 │        46 │        46 │        46 │       441 │
├──────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Malloc (total) *         │         0 │         0 │         0 │         0 │         0 │         0 │         0 │       441 │
├──────────────────────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┼───────────┤
│ Time (wall clock) (ns) * │      2134 │      2216 │      2241 │      2265 │      2292 │      2388 │      2737 │       441 │
╘══════════════════════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╧═══════════╛

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can just assume that this is about inlining thresholds.

@fabianfett fabianfett merged commit 0b600fc into main Mar 10, 2026
56 of 57 checks passed
@fabianfett fabianfett deleted the ff-make-hpack-encoding-2x-faster branch March 10, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants