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

De-duplicate values and hash in packed leaves #10

Open
michaelsproul opened this issue Jun 19, 2023 · 0 comments
Open

De-duplicate values and hash in packed leaves #10

michaelsproul opened this issue Jun 19, 2023 · 0 comments
Assignees

Comments

@michaelsproul
Copy link
Member

@paulhauner observed that we could save space in memory by storing the values of packed leaves inside the Hash256. There's no hashing of packed leaves, and they always fit within 32 bytes, so in theory there's no need to duplicate them in memory as we do currently:

#[derive(Debug, Derivative, Arbitrary)]
#[derivative(PartialEq, Hash)]
pub struct PackedLeaf<T: TreeHash + Clone> {
#[derivative(PartialEq = "ignore", Hash = "ignore")]
#[arbitrary(with = arb_rwlock)]
pub hash: RwLock<Hash256>,
pub(crate) values: Vec<T>,
}

The easiest approach is probably to retain the Has256 and read the smaller sized integers off it on-demand, but we could also take the opposite approach: store the integers and compute the Hash256 on-demand. This latter option may be preferable as the Hash256 should only be read once, when hashing the parent, whereas the values may be read numerous times. On the other hand, the Hash256 is allocated in-line rather than on the heap, so is probably more memory-efficient, and quicker to perform copy-on-write updates on.

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

No branches or pull requests

2 participants