-
Notifications
You must be signed in to change notification settings - Fork 21
De-duplicate values and hash in packed leaves #10
Description
@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:
Lines 8 to 15 in 4035d25
| #[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.