KokaKiwi / rust-hex

A basic crate to encode values to hexadecimal representation. Originally extracted from rustc-serialize.
https://crates.io/crates/hex
Apache License 2.0
201 stars 55 forks source link

Improve performance of decoding #62

Open taiki-e opened 3 years ago

taiki-e commented 3 years ago

This change makes decoding about 10x faster than the current implementation, on my machine.

Before:

hex_decode              time:   [128.28 us 129.41 us 130.70 us]

After:

hex_decode              time:   [12.206 us 12.242 us 12.284 us]                        
Benchmarks per commit Current main branch (aa8f3001fed80718ea8e33ab5e278351d3ef5036) ``` hex_decode time: [128.28 us 129.41 us 130.70 us] ``` First commit of this PR: Use lookup table for decoding (870590e2284250c4c8789955f7664d33dc15a2ae) ``` hex_decode time: [63.538 us 63.936 us 64.419 us] change: [-50.833% -50.462% -50.088%] (p = 0.00 < 0.05) Performance has improved. ``` Second commit of this PR: Inline val function (3b75b32a17153dc467fc403bbf60bf99fb9c0a72) ``` hex_decode time: [32.263 us 32.382 us 32.521 us] change: [-49.441% -49.098% -48.682%] (p = 0.00 < 0.05) Performance has improved. ``` Third commit of this PR: Use chunks_exact instead of chunks (ff1d11514e0eb7116aca65f8f69d58a061ee2382) ``` hex_decode time: [24.701 us 24.814 us 24.936 us] change: [-24.459% -23.911% -23.395%] (p = 0.00 < 0.05) Performance has improved. ``` Fourth commit of this PR: Use decode_to_slice in Vec::from_hex (4fd0ed8d81c24785c44a33a54f7ccfeb94d13999) ``` hex_decode time: [16.060 us 16.297 us 16.608 us] change: [-35.137% -34.468% -33.556%] (p = 0.00 < 0.05) Performance has improved. ``` Fifth commit of this PR: Inline decode_to_slice function (3e2aa25cd58c6aca9aefec7c40cc48aa7c2b118b) ``` hex_decode time: [12.206 us 12.242 us 12.284 us] change: [-21.954% -20.254% -18.150%] (p = 0.00 < 0.05) Performance has improved. ```
codecov-commenter commented 3 years ago

Codecov Report

Merging #62 (f3251bd) into main (aa8f300) will decrease coverage by 0.44%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #62      +/-   ##
==========================================
- Coverage   94.55%   94.11%   -0.45%     
==========================================
  Files           4        4              
  Lines         147      153       +6     
==========================================
+ Hits          139      144       +5     
- Misses          8        9       +1     
Impacted Files Coverage Δ
tests/version-number.rs 100.00% <ø> (ø)
src/lib.rs 96.99% <100.00%> (-0.65%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update aa8f300...f3251bd. Read the comment docs.