Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: do less allocs in hasher (#287)
Have found few places after #285 that can be improved a bit more without going into enigma mode™: ``` $ go-perftuner bstat a.txt c.txt args: [a.txt c.txt]name old time/op new time/op delta ComputeRoot/64-leaves-10 37.5µs ± 1% 34.2µs ± 2% -8.76% (p=0.000 n=8+10) ComputeRoot/128-leaves-10 73.9µs ± 0% 68.6µs ± 2% -7.21% (p=0.000 n=9+10) ComputeRoot/256-leaves-10 151µs ± 2% 140µs ± 4% -6.91% (p=0.000 n=9+10) ComputeRoot/20k-leaves-10 14.9ms ± 2% 13.2ms ± 4% -11.53% (p=0.000 n=10+10) name old alloc/op new alloc/op delta ComputeRoot/64-leaves-10 57.6kB ± 0% 31.7kB ± 0% -45.02% (p=0.000 n=10+10) ComputeRoot/128-leaves-10 109kB ± 0% 57kB ± 0% -47.83% (p=0.000 n=10+10) ComputeRoot/256-leaves-10 224kB ± 0% 120kB ± 0% -46.45% (p=0.000 n=10+10) ComputeRoot/20k-leaves-10 26.2MB ± 0% 12.3MB ± 0% -53.11% (p=0.000 n=9+10) name old allocs/op new allocs/op delta ComputeRoot/64-leaves-10 590 ± 0% 527 ± 0% -10.68% (p=0.000 n=10+10) ComputeRoot/128-leaves-10 1.17k ± 0% 1.04k ± 0% -10.86% (p=0.000 n=10+10) ComputeRoot/256-leaves-10 2.33k ± 0% 2.07k ± 0% -10.95% (p=0.000 n=10+10) ComputeRoot/20k-leaves-10 181k ± 0% 161k ± 0% -11.08% (p=0.000 n=10+10) ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Optimized hashing methods for improved efficiency. - Simplified data preparation for leaf and node hashing. - Reduced unnecessary memory allocations in hash calculations. - **Tests** - Enhanced the `TestEmptyRoot` function with sub-tests for better validation. - Improved variable naming for clarity in test cases. - Updated assertions for better readability in test results. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
- Loading branch information