parity-common
parity-common copied to clipboard
Performence issue + wrapping_{add,sub}
Hello, first of all, i'm new with rust, so i could miss some concept...
i have a MerkleTree in rust, and i was using the ethnum library. the library was missing the Serialize/Deserialize, and your library is more complete. so i decided to switched.
Just i was missing those function:
which i implemented that way:
pub fn wrapping_add(lhs: U256, rhs: U256) -> U256 {
match lhs.checked_add(rhs) {
None => {
if lhs > rhs {
lhs - (U256::MAX - rhs) - 1
} else {
rhs - (U256::MAX - lhs) - 1
}
}
Some(x) => x,
}
}
pub fn wrapping_sub(lhs: U256, rhs: U256) -> U256 {
match lhs.checked_sub(rhs) {
None => {
if lhs > rhs {
U256::MAX - (rhs - lhs) + 1
} else {
U256::MAX - (rhs - lhs) + 1
}
}
Some(x) => x,
}
}
Maybe it's because of those functions... (or something else ?) but my MerkleTree(16 floors) creation + insert 1 leaf went from ~6s to 19s...
Do you have any tips or advice to reduce this time ?