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

make Huffman methods class methods to avoid unnecessary allocations #9

Merged
merged 2 commits into from
Jul 28, 2024

Conversation

froydnj
Copy link
Contributor

@froydnj froydnj commented Jul 25, 2024

Protocol::HPACK::Huffman doesn't maintain any state, so there's no reason for encode/decode to be instance methods. Making them class methods means we can avoid allocating instances during header encoding/decoding, which improves performance (~2% on my machine, but the benchmark is a bit noisy).

Types of Changes

  • Performance improvement.

Contribution

@ioquatix ioquatix force-pushed the froydnj-no-allocate-huffman branch from 4d26e91 to a259093 Compare July 28, 2024 05:17
@ioquatix ioquatix force-pushed the froydnj-no-allocate-huffman branch from a259093 to 8581688 Compare July 28, 2024 05:17
@ioquatix ioquatix merged commit 33ad58a into socketry:main Jul 28, 2024
19 of 20 checks passed
@ioquatix
Copy link
Member

Thanks for this nice improvement.

@ioquatix
Copy link
Member

Some rough comparisons:

HEAD

________________________________________________________
Executed in   18.68 secs    fish           external
   usr time   17.59 secs  326.00 micros   17.59 secs
   sys time    1.03 secs  146.00 micros    1.03 secs

Before your changes

________________________________________________________
Executed in   21.79 secs    fish           external
   usr time   20.63 secs  323.00 micros   20.63 secs
   sys time    1.11 secs  145.00 micros    1.11 secs

@froydnj
Copy link
Contributor Author

froydnj commented Jul 29, 2024

Some rough comparisons:

HEAD

________________________________________________________
Executed in   18.68 secs    fish           external
   usr time   17.59 secs  326.00 micros   17.59 secs
   sys time    1.03 secs  146.00 micros    1.03 secs

Before your changes

________________________________________________________
Executed in   21.79 secs    fish           external
   usr time   20.63 secs  323.00 micros   20.63 secs
   sys time    1.11 secs  145.00 micros    1.11 secs

Cool! I've pushed #12 and I have a slightly more complex change for improving header encoding/decoding that'll have to wait until tomorrow.

@froydnj
Copy link
Contributor Author

froydnj commented Jul 29, 2024

And thank you for merging all of these so quickly!

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.

2 participants