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

Pre-allocate len of FixedVector during Decode #34

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

paulhauner
Copy link
Member

@paulhauner paulhauner commented Nov 25, 2024

Use Vec::with_capacity when decoding a FixedVector, based on num_items.

num_items has been checked against N::to_usize() (where N is the fixed length of the vector). This protects us against memory explosions, as is common with pre-allocations.

When flame-graphing SSZ block decoding we can see that growing the logs_bloom FixedVector during ExecutionPayload decoding takes some time.

Notably, this refactor didn't make a significant improvement in block decoding times. However I still think it's worth including because it is kinder to the machine.

Benchmarking

Here's the flamegraph from before this change was implemented. It requires some searching to find the SSZ decode function, but it's there. Screenshots below.

Entire Block Decoding

Screenshot 2024-11-26 at 6 40 08 AM

Zoomed into FixedVector::from_ssz_bytes

Screenshot 2024-11-26 at 6 43 50 AM

Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

Looks great!

@paulhauner paulhauner merged commit 9e59ff9 into sigp:main Nov 25, 2024
5 checks passed
@paulhauner paulhauner deleted the fixed-vec-prealloc branch November 25, 2024 23:19
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.

2 participants