Repository navigation
Bound SSZ list pre-allocation - #87
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #87 +/- ##
==========================================
+ Coverage 82.28% 82.40% +0.11%
==========================================
Files 14 14
Lines 1225 1233 +8
==========================================
+ Hits 1008 1016 +8
Misses 217 217 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
michaelsproul
left a comment
There was a problem hiding this comment.
Not sure if this really does anything for the Vec or ProgressiveList case. We will avoid immediately pre-allocating, but AFAICT there's nothing to stop us from consuming the full iterator and allocating the same amount by the time we finish decoding. It helps for oversized length hints, but AFAICT we always derive the length hints from the iterator, not the offsets, so we are not prone to over-allocating anyway.
Further, the decode path for a progressive list of fixed-size items (a common case, including PayloadAttestation/Attestation), doesn't use the TryFromIter impl until after it has already collected into a Vec (which uses the impl From<Iterator<Item = Result<_, _>>> for Result<Vec<_>, _> from the std library):
|
yeah in the "honest" input case we would consume the full iterator. But the 10MiB network limits help in that case. For example a block with too many attestations still needs to be under the 10MiB limit and decoding that object wouldn't take up too much memory. I think maybe like 50-60mib at worst From what I understand in For the fixed size case I think thats okay, the size hint is |
|
Ohhhhh I missed that. I didn't clock that the iterator was over Satisfied that this is correctly patching that gap! Thanks! |
Progressive lists carry no length limit. An SSZ input can claim a huge item count and force a giant
Vec::with_capacitypre-allocation before any element is read.This bounds the pre-allocation in
VecandSmallVectry_from_iterto a fixed 1 MiB. The collection can still grow, so a valid list is never rejected.