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

feat: HashBuilder::add_leaf_unchecked #64

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

hai-rise
Copy link
Contributor

@hai-rise hai-rise commented Nov 30, 2024

We're stress-testing live state root calculation in Reth that led back to this crate (thanks for the great work!).

So, this assert takes ~7.7% of HashBuilder::add_leaf and ~1% of StateRoot::calculate:

pub fn add_leaf(&mut self, key: Nibbles, value: &[u8]) {
assert!(key > self.key, "add_leaf key {:?} self.key {:?}", key, self.key);

image

This PR adds an unchecked version for performance-critical users who guarantee keys are added in sorted order (like Reth with its node iterator).

Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alternatively we could convert this to a debug_assert

thoughts @DaniPopes @rkrasiuk ?

@DaniPopes
Copy link
Member

DaniPopes commented Nov 30, 2024

We can have this, but we should have the assert be a debug_assert in the unchecked function too

@hai-rise
Copy link
Contributor Author

hai-rise commented Dec 2, 2024

I've added the debug_assert for now. Should I look into CI and should we add HashBuilderError like ProofVerificationError in the future?

@rkrasiuk
Copy link
Member

rkrasiuk commented Dec 3, 2024

supportive of keeping assert in reg method and having unchecked with debug_assert

@mattsse mattsse merged commit d7b9617 into alloy-rs:main Dec 4, 2024
15 of 21 checks passed
@hai-rise hai-rise deleted the add-leaf-unchecked branch December 4, 2024 15:45
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

Successfully merging this pull request may close these issues.

4 participants