Pre-allocate len of FixedVector
during Decode
#34
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use
Vec::with_capacity
when decoding aFixedVector
, based onnum_items
.num_items
has been checked againstN::to_usize()
(whereN
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
duringExecutionPayload
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
Zoomed into
FixedVector::from_ssz_bytes