ralexstokes / ssz-rs

Implementation of ethereum's `ssz`
Apache License 2.0
103 stars 41 forks source link

Avoid allocating default container when deserializing #99

Closed ralexstokes closed 1 year ago

ralexstokes commented 1 year ago

Right now, the SimpleSerialize proc macro will allocate a Default::default() instance when deserializing and then set each field accordingly.

We can save some space by parsing the input to get all relevant spans (along w/ validating invariants of the data) and then making an instance of the type once after we know where to segment the incoming encoding for each field.

This PR implements this change.

codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 81.69% and project coverage change: +0.37% :tada:

Comparison is base (aa625fc) 77.06% compared to head (abb7026) 77.44%. Report is 1 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #99 +/- ## ========================================== + Coverage 77.06% 77.44% +0.37% ========================================== Files 17 17 Lines 798 869 +71 ========================================== + Hits 615 673 +58 - Misses 183 196 +13 ``` | [Files Changed](https://app.codecov.io/gh/ralexstokes/ssz-rs/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alex+Stokes) | Coverage Δ | | |---|---|---| | [ssz-rs/src/de.rs](https://app.codecov.io/gh/ralexstokes/ssz-rs/pull/99?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Alex+Stokes#diff-c3N6LXJzL3NyYy9kZS5ycw==) | `80.15% <81.69%> (+1.97%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.