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

perf(primitives): avoid cloning receipts when calculating the root #8350

Merged
merged 1 commit into from
May 22, 2024

Conversation

DaniPopes
Copy link
Member

@DaniPopes DaniPopes commented May 22, 2024

We can re-use the ref-type ReceiptWithBloomRef instead of cloning into ReceiptWithBloom to calculate the logs blooms and receipt root.

Drive-by: use encode_fixed_size to RLP encode the receipt index on the stack.

Closes #8340

@DaniPopes DaniPopes requested a review from shekhirin May 22, 2024 18:38
@github-actions github-actions bot added A-execution Related to the Execution and EVM C-perf A change motivated by improving speed, memory usage or disk footprint labels May 22, 2024
@@ -104,20 +101,25 @@ pub fn calculate_receipt_root_optimism(
ordered_trie_root_with_encoder(receipts, |r, buf| r.encode_inner(buf, false))
}

/// Calculates the receipt root for a header.
pub fn calculate_receipt_root_ref(receipts: &[ReceiptWithBloomRef<'_>]) -> B256 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

sigh, would be nice to have one method for both cases, unsure if it's possible though

@DaniPopes DaniPopes force-pushed the dani/perf-receipt-root branch from 87fe8d5 to 87d7357 Compare May 22, 2024 18:45
@DaniPopes DaniPopes force-pushed the dani/perf-receipt-root branch from 87d7357 to 40155a1 Compare May 22, 2024 18:48
@DaniPopes DaniPopes requested a review from mattsse as a code owner May 22, 2024 18:48
@DaniPopes DaniPopes enabled auto-merge May 22, 2024 18:48
Comment on lines +120 to +122
/// NOTE: Prefer [`calculate_receipt_root_optimism`] if you have log blooms memoized.
#[cfg(feature = "optimism")]
pub fn calculate_receipt_root_ref_optimism(
pub fn calculate_receipt_root_no_memo_optimism(
Copy link
Collaborator

Choose a reason for hiding this comment

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

not to self to move this shortly


/// Calculates the bloom filter for the receipt and returns the [ReceiptWithBloomRef] container
/// type.
pub fn with_bloom_ref(&self) -> ReceiptWithBloomRef<'_> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

as_bloom_ref ? maybe

Copy link
Member Author

Choose a reason for hiding this comment

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

thats what the type is called, it would also make more sense to highlight that this is slow and not have Into impls

@DaniPopes DaniPopes added this pull request to the merge queue May 22, 2024
Merged via the queue into main with commit 7653e81 May 22, 2024
30 checks passed
@DaniPopes DaniPopes deleted the dani/perf-receipt-root branch May 22, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-execution Related to the Execution and EVM C-perf A change motivated by improving speed, memory usage or disk footprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid cloning when verifying receipts root after the EVM execution
3 participants