Skip to content

De-duplicate values and hash in packed leavesΒ #10

Open
@michaelsproul

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:

#[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.

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions