Commit 8c942b4
perf(tip5): Avoid one permutation in
The last step of `hash_varlen` is to read out the hash from the state.
Previous this reading-out was followed by a permutation. But since the
of the sponge is dropped after the termination of this function, the
last permutation is not needed.
For short inputs to `hash_varlen` this gives a significant speedup.
Short instances of `hash_varlen` is used downstream by `neptune-core` in
the pow-guessing process, where this change reduces the number of
permutations from nine to seven.
Added benchmark shows a 28 % speedup when running `hash_varlen` on an
input of length 10. For longer input lengths, this speedup will approach
zero.
Shoutout to @macro-ss for identifying this speedup.
Benchmark results, with this change:
```bash
$ cargo criterion --bench tip5
Compiling twenty-first v0.48.0 (/home/thv/repos/twenty-first/twenty-first)
Finished `bench` profile [optimized] target(s) in 4.40s
Gnuplot not found, using plotters backend
tip5/hash_10/Tip5 / Hash 10/10
time: [532.41 ns 532.71 ns 533.02 ns]
change: [-0.2022% +0.0630% +0.2673%] (p = 0.66 > 0.05)
No change in performance detected.
tip5/hash_pair/Tip5 / Hash Pair/pair
time: [531.36 ns 533.53 ns 536.38 ns]
change: [-1.4081% -1.0392% -0.6529%] (p = 0.00 < 0.05)
Change within noise threshold.
tip5/hash_varlen/Tip5 / Hash Variable Length/16384
time: [1.0669 ms 1.0682 ms 1.0699 ms]
change: [+2.3852% +2.6962% +2.9802%] (p = 0.00 < 0.05)
Performance has regressed.
tip5/hash_varlen/Tip5 / Hash Variable Length/10
time: [1.3163 µs 1.3181 µs 1.3198 µs]
change: [-28.468% -28.273% -28.108%] (p = 0.00 < 0.05)
Performance has improved.
tip5/parallel/Tip5 / Parallel Hash/65536
time: [1.0509 ms 1.0606 ms 1.0724 ms]
change: [-7.4722% -1.6295% +4.5693%] (p = 0.62 > 0.05)
No change in performance detected.
```
Co-authored-by: marco-storswift <[email protected]>hash_varlen (#252)1 parent ff0ec3a commit 8c942b4
2 files changed
+17
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
37 | 39 | | |
38 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
39 | 46 | | |
| 47 | + | |
| 48 | + | |
40 | 49 | | |
41 | | - | |
| 50 | + | |
42 | 51 | | |
43 | | - | |
| 52 | + | |
44 | 53 | | |
45 | 54 | | |
46 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
630 | | - | |
| 630 | + | |
631 | 631 | | |
632 | 632 | | |
633 | 633 | | |
634 | | - | |
| 634 | + | |
| 635 | + | |
635 | 636 | | |
636 | | - | |
| 637 | + | |
637 | 638 | | |
638 | 639 | | |
639 | 640 | | |
| |||
0 commit comments