onflow / atree

Atree provides scalable arrays and scalable ordered maps.
https://onflow.org
Apache License 2.0
39 stars 13 forks source link

Fix slab size when resetting mutable storable in Array #336

Closed fxamacker closed 10 months ago

fxamacker commented 10 months ago

Updates #292 #335

Changes

Recompute slab size by adding all element sizes instead of using the size diff of old and new element because oldElem can be the same storable when the same value is reset and oldElem.ByteSize() can equal storable.ByteSize().

Given this, size diff of the old and new element can be 0 even when its actual size changed.

This is prep work for atree inlining to prevent a bug from surfacing.


codecov-commenter commented 10 months ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.08% :tada:

Comparison is base (74e19aa) 65.24% compared to head (dda0495) 65.32%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #336 +/- ## ========================================== + Coverage 65.24% 65.32% +0.08% ========================================== Files 14 14 Lines 8761 8773 +12 ========================================== + Hits 5716 5731 +15 + Misses 2327 2325 -2 + Partials 718 717 -1 ``` | [Files Changed](https://app.codecov.io/gh/onflow/atree/pull/336?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onflow) | Coverage Δ | | |---|---|---| | [array.go](https://app.codecov.io/gh/onflow/atree/pull/336?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onflow#diff-YXJyYXkuZ28=) | `70.69% <100.00%> (+0.15%)` | :arrow_up: | ... and [1 file with indirect coverage changes](https://app.codecov.io/gh/onflow/atree/pull/336/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onflow)

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

fxamacker commented 10 months ago

@ramtinms

looks good to me, Just to confirm my understanding this only iterates over the size of values of the current slab and nothing beyond that? if for example we have an array with many underlying slabs, changes in one element doesn't require the whole array to go and scan all the slabs ?

Yes, this only iterates over the sizes of elements in current slab. It doesn't require scanning of the whole array.