-
Notifications
You must be signed in to change notification settings - Fork 277
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
[suggestion]: MerkleTree
optimization
#2396
Comments
There's a few points. This is a consequence of years of experience in optimising software, so I'd err on the side of caution.
Only at the language level. In reality most CPUs ignore the branch conditions execute the likely branch, and only backtrack to the condition once the branch misprediction takes place. If we don't use monadics, and instead operate on
Also no. I'd argue that if In other words we can have the cake and eat it too in terms of memory layout savings. A similar thing is done to the built-in type |
I think that we should explore the approach of making |
MerkleTree
optimizationMerkleTree
optimization
However i'm not sure how we can make |
That’s the clever bit. if it were u8;16 you could just pack that into a single u128. That trick doesn’t quite work with u8: 32 but there must be a way. |
Actually, we could pack it into two u128s, and mark the less significant bits as nonzero. We then set the LSB to 1 for all valid hashes. If we want to be pedantic, this sacrifices one bit for all other hashes. |
We should be careful as |
With merge of #3012 there is no need to remove |
Explore tradeoffs between time and space efficiency (skipping hash calculations v.s. having no wrappers).
Currently, a node is represented as
Option<HashOf<T>>
.This can benefit from skipping empty (
None
) nodes in the hash calculation from the leaves to the root of the tree, while increases the memory footprint by the amount of the wrapper.HashOf<T>
may be an alternative for the node representation.In that case, an empty node can be represented as
Hash::zeroed().typed()
.This is advantageous in terms of memory footprint, while increases the hash calculation cost since there is no distinction in types between empty and non-empty nodes
The text was updated successfully, but these errors were encountered: