-
Notifications
You must be signed in to change notification settings - Fork 69
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
Improve TrieCache size by reducing size_of NodeOwned #216
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Alexandru Gheorghe <[email protected]>
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.
Nice work 👍
I just want some improvements and then we almost need no changes.
Signed-off-by: Alexandru Gheorghe <[email protected]>
Done, thank you! |
Signed-off-by: Alexandru Gheorghe <[email protected]>
Signed-off-by: Alexandru Gheorghe <[email protected]>
/// Returns the number of children. | ||
pub fn len(&self) -> usize { | ||
self.0.len() | ||
} |
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.
nit: Might be good to have an is_empty
for a complete API if we are exposing this to the user (https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty)
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.
Nicely done! 4x reduction is amazing 🚀
NodeOwned uses static arrays to represent the children of a
NodeOwned::Branch
andNodeOwned::NibbledBranch
, because the enum's size is the size of largest variant it ends up occupying 752 bytes.The substrate ShareTrieCache ends up keeping a hash map with elements of NodeOwned, so it's size quickly balloons, although most of the children seem to be empty.
The trie cache size benefits greatly from using a dynamic array instead of static one: paritytech/polkadot-sdk#6131 (comment), using westend-asset-hub, we can see a ~4 times reduction in memory size for the TrieCache.
Fixes: paritytech/polkadot-sdk#7386