Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to String-backed HPACK representations. #89

Merged
merged 2 commits into from
Apr 12, 2019

Conversation

Lukasa
Copy link
Contributor

@Lukasa Lukasa commented Apr 10, 2019

Motivation:

When originally written our HPACK implementation targetted Swift 4.2,
which had performance issues when storing mostly-ASCII data in Strings.
For this reason we had a number of data types that used ByteBuffers as
their backing storage and reified Strings when necessary.

In Swift 5 this is no longer worthwhile: in fact, it imposes performance
penalties above and beyond simply using the Strings. For this reason, we
should move to a simpler model where we simply store Strings again.

Modifications:

  • Rewrote all HPACK data structures to use Strings as their backing store.
  • Removed now-redundant genericism.
  • Removed now-unnecessary StringRing data structure and associated tests.

Result:

Faster performance in almost all cases.

Motivation:

When originally written our HPACK implementation targetted Swift 4.2,
which had performance issues when storing mostly-ASCII data in Strings.
For this reason we had a number of data types that used ByteBuffers as
their backing storage and reified Strings when necessary.

In Swift 5 this is no longer worthwhile: in fact, it imposes performance
penalties above and beyond simply using the Strings. For this reason, we
should move to a simpler model where we simply store Strings again.

Modifications:

- Rewrote all HPACK data structures to use Strings as their backing store.
- Removed now-redundant genericism.
- Removed now-unnecessary StringRing data structure and associated tests.

Result:

Faster performance in almost all cases.
@Lukasa Lukasa added the semver/patch No public API change. label Apr 10, 2019
@Lukasa Lukasa added this to the 1.0.2 milestone Apr 10, 2019
@Lukasa Lukasa requested a review from weissi April 10, 2019 16:08
@Lukasa
Copy link
Contributor Author

Lukasa commented Apr 10, 2019

This change provides a substantial performance boost. I benchmarked using h2load to provide a fairly unrepresentative workload (doing a bunch of GETs and sending back almost no body) which puts a lot of strain on the HPACK implementation. Before this patch:

                     min         max         mean         sd        +/- sd
time for request:   359.58ms    508.06ms    400.98ms     23.49ms    62.69%
req/s           :     229.99      260.83      248.95       13.88    64.00%

After this patch:

                     min         max         mean         sd        +/- sd
time for request:   116.21ms    428.62ms    187.57ms     33.18ms    86.33%
req/s           :     481.62      565.77      532.60       31.92    57.00%

That's a more than 2x speedup, as well as a substantial decrease in latency in any case that was using indexed headers.

@weissi
Copy link
Member

weissi commented Apr 10, 2019

AMAZING

@AlanQuatermain
Copy link
Contributor

AlanQuatermain commented Apr 10, 2019 via email

@Lukasa
Copy link
Contributor Author

Lukasa commented Apr 10, 2019

Yup, it was very subtle code and being able to performantly remove it is a big win. It also reduces the surface area for further optimisation, so profiling should do a better job finding expensive operations.

Copy link
Member

@weissi weissi left a comment

Choose a reason for hiding this comment

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

looks good to me, thank you!

@Lukasa Lukasa merged commit ddc9821 into apple:master Apr 12, 2019
@Lukasa Lukasa deleted the cb-hpack-headers-string-backed branch April 12, 2019 11:42
@Lukasa Lukasa added semver/minor Adds new public API. and removed semver/patch No public API change. labels Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants