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

Faster hex encoding #144

Merged
merged 3 commits into from Sep 13, 2023
Merged

Faster hex encoding #144

merged 3 commits into from Sep 13, 2023

Conversation

novacrazy
Copy link
Collaborator

Optimizes the standard encoding, plus adds support for using the faster-hex crate for SIMD-accelerated encoding.

Expand for benchmarks table
N Before After Change
1 16.220 ns 16.010 ns -1.30%
2 17.035 ns 16.019 ns -5.96%
4 17.765 ns 17.000 ns -4.31%
8 18.798 ns 18.640 ns -0.84%
12 21.002 ns 20.106 ns -4.27%
15 22.648 ns 21.692 ns -4.22%
16 22.495 ns 15.583 ns -30.73%
32 32.556 ns 16.930 ns -48.00%
64 50.232 ns 19.022 ns -62.13%
100 70.175 ns 23.459 ns -66.57%
128 87.228 ns 20.423 ns -76.59%
160 105.057 ns 22.228 ns -78.84%
255 156.836 ns 34.361 ns -78.09%
256 182.728 ns 25.557 ns -86.01%
500 293.572 ns 41.154 ns -85.98%
512 352.274 ns 38.409 ns -89.10%
900 610.794 ns 63.040 ns -89.68%
1023 585.836 ns 74.845 ns -87.22%
1024 586.594 ns 65.048 ns -88.91%
1025 505.389 ns 72.909 ns -85.57%
2048 975.273 ns 110.846 ns -88.63%
4096 1945.770 ns 201.676 ns -89.64%
5000 2343.561 ns 250.155 ns -89.33%
10000 4698.586 ns 509.036 ns -89.17%

It's worth noting at least 10-16ns of those benchmarks seems to be spent on non-encoding things. In fact it was made worse when I upgraded to Rust 1.72.0 today, but only in terms of that base offset.

I'm not super happy about the unsafe usage here, but when mixing the fmt precision in like that LLVM has a harder time reasoning with it.

@novacrazy
Copy link
Collaborator Author

Re-ran benchmarks with Rust 1.73.0-beta, which includes an LLVM upgrade:

Expand for benchmarks table
N Before After Change
1 9.153 ns 9.202 ns 0.53%
2 9.820 ns 9.293 ns -5.37%
4 11.704 ns 9.952 ns -14.97%
8 13.164 ns 11.583 ns -12.01%
12 13.737 ns 13.645 ns -0.67%
15 15.083 ns 14.719 ns -2.42%
16 16.915 ns 12.643 ns -25.26%
32 28.896 ns 14.379 ns -50.24%
64 47.562 ns 15.429 ns -67.56%
100 75.660 ns 19.488 ns -74.24%
128 83.917 ns 18.227 ns -78.28%
160 109.399 ns 23.072 ns -78.91%
255 156.394 ns 32.404 ns -79.28%
256 159.777 ns 24.415 ns -84.72%
500 288.924 ns 39.826 ns -86.22%
512 296.679 ns 36.177 ns -87.81%
900 548.176 ns 58.511 ns -89.33%
1023 583.620 ns 73.875 ns -87.34%
1024 614.904 ns 63.397 ns -89.69%
1025 566.742 ns 68.560 ns -87.90%
2048 1084.768 ns 113.175 ns -89.57%
4096 2146.710 ns 198.601 ns -90.75%
5000 3290.758 ns 245.378 ns -92.54%
10000 5580.791 ns 488.860 ns -91.24%

Old version got slower, new version gets faster. Neat.

@novacrazy novacrazy merged commit 9b12a1a into 1.0 Sep 13, 2023
4 checks passed
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.

None yet

1 participant