-
Notifications
You must be signed in to change notification settings - Fork 6
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
optimize hash_tree_root using hashtree #35
Conversation
ssz_serialization/merkleization.nim
Outdated
|
||
func best_sha256_implementation(): Hasher {.importc.} | ||
|
||
let digest64* = block: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
digest64 is a really bad name. Maybe digest2x
or digest_2way
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well .. it's 64 bytes which is the significant requirement here .. ie unlike the other digest functions, it only works for blocks of that length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just call it digestBlockSize
:)
ssz_serialization/merkleization.nim
Outdated
h.update a | ||
h.update b | ||
h.update c | ||
func digest(a, b, c: openArray[byte]): Digest {.noinit.} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When does this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when joining a 32-byte data chunk with a <32-byte chunk - c
is the zero padding mandated by ssz
6397a6a
to
84985e0
Compare
8685304
to
9aeaa38
Compare
9aeaa38
to
fd5f3ee
Compare
20% from digest64 10% from working around nim-lang/Nim#20232 brings `hash_tree_root(BeaconState)` down ~480ms to ~320ms from the padding optimization alone - further optimization possible by parallelizing the hashing of each tree level, but that requires more surgery.
status-im/nim-ssz-serialization#35 brings in https://github.com/prysmaticlabs/hashtree as a supported backend for SHA256, giving a nice little performance boost to all hash_tree_root calls on supported platforms / compilers. Expected gains are on the order of 30% which in the case of a replayed state nets us 0.2-0.3s improvement. More about this design here: https://hackmd.io/@potuz/BJyrx9DOF - kudos to @potuz for this excellent library!
brings
hash_tree_root(BeaconState)
down ~800ms to ~660ms - further optimization is possible by hashing multiple blocks in a single call, but this requires more significant surgery.