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

Add blake3 benchmark for merkledb #3349

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

StephenButtolph
Copy link
Contributor

Why this should be merged

BLAKE3 is a popular alternative to SHA256 which may be able to be configured to out-perform SHA256. Related twitter convo.

goos: darwin
goarch: arm64
pkg: github.com/ava-labs/avalanchego/x/merkledb
Benchmark_SHA256_HashNode/empty_node-12         	14813816	        85.51 ns/op	       0 B/op	       0 allocs/op
Benchmark_SHA256_HashNode/has_value-12          	13826523	        85.75 ns/op	       0 B/op	       0 allocs/op
Benchmark_SHA256_HashNode/has_key-12            	16249858	        74.29 ns/op	       0 B/op	       0 allocs/op
Benchmark_SHA256_HashNode/1_child-12            	 8004384	       142.2 ns/op	       0 B/op	       0 allocs/op
Benchmark_SHA256_HashNode/2_children-12         	 5870755	       203.5 ns/op	       0 B/op	       0 allocs/op
Benchmark_SHA256_HashNode/16_children-12        	 1000000	      1052 ns/op	       0 B/op	       0 allocs/op
Benchmark_BLAKE3_HashNode/empty_node-12         	 3500679	       346.3 ns/op	       0 B/op	       0 allocs/op
Benchmark_BLAKE3_HashNode/has_value-12          	 3406614	       360.3 ns/op	       0 B/op	       0 allocs/op
Benchmark_BLAKE3_HashNode/has_key-12            	 3430132	       348.2 ns/op	       0 B/op	       0 allocs/op
Benchmark_BLAKE3_HashNode/1_child-12            	 2954095	       426.4 ns/op	       0 B/op	       0 allocs/op
Benchmark_BLAKE3_HashNode/2_children-12         	 2223614	       547.5 ns/op	       0 B/op	       0 allocs/op
Benchmark_BLAKE3_HashNode/16_children-12        	  660697	      1837 ns/op	       0 B/op	       0 allocs/op
PASS

How this works

Because golang generics aren't great... This copies the sha256 hasher implementation and uses a blake3 hasher. I'm not aware of a way to share this code without introducing memory allocations (as passing a buffer into an interface will introduce memory allocations and golang does not specialize generic functions for interfaces).

How this was tested

  • Added unit tests + benchmarks.

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.

1 participant