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

Change OrderedMap.Get() to return Value instead of Storable #318

Merged
merged 1 commit into from
Jun 29, 2023

Conversation

fxamacker
Copy link
Member

Closes #317
Updates #296 #292

Description

This PR changes OrderedMap.Get() to return Value instead of Storable.

Currently, OrderedMap.Get() returns Storable and client converts returned Storable to Value. However, it only makes sense to return Storable if client needs to remove register (slab) by StorageID (StorageIDStorable).

Get() should only provide value without possibility of client manipulating the underlying storable.

This is prep work for Atree Register Inlining (#292) and will also harden the API.

Corresponding PR for Array.Get() is PR #316.


  • Targeted PR against main branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

This commit changes OrderedMap.Get() to return Value instead
of Storable.

Currently, OrderedMap.Get() returns Storable and client converts
returned Storable to Value.  However, it only makes sense to
return Storable if client needs to remove register (slab) by
StorageID (StorageIDStorable).

Get() should only provide value without possibility of client
manipulating the underlying storable.
@fxamacker fxamacker added improvement breaking change changes to API that can break programs using Atree's API labels Jun 27, 2023
@fxamacker fxamacker requested a review from ramtinms as a code owner June 27, 2023 17:41
@fxamacker fxamacker self-assigned this Jun 27, 2023
@fxamacker fxamacker requested a review from turbolent as a code owner June 27, 2023 17:41
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

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

Nice! 👌

I checked Cadence and confirmed that it always converts the storable to a value anyways.

I also noticed that it uses Get for existence checks. Once atree starts to always convert to a value, this could become expensive in the case where the key exists: We would pay for a conversion and then the result is discarded. I opened onflow/cadence#2618 to improve / prevent that

@fxamacker fxamacker merged commit f54dc2f into main Jun 29, 2023
fxamacker added a commit to onflow/cadence that referenced this pull request Jun 29, 2023
This commit updates Cadence to use new Atree API
- Array.Get()
- OrderedMap.Get()
- MaxInlineArrayElementSize()
- MaxInlineMapKeySize()

For more info, see Atree PRs:
- onflow/atree#314
- onflow/atree#316
- onflow/atree#318
turbolent pushed a commit to onflow/cadence that referenced this pull request Jan 26, 2024
This commit updates Cadence to use new Atree API
- Array.Get()
- OrderedMap.Get()
- MaxInlineArrayElementSize()
- MaxInlineMapKeySize()

For more info, see Atree PRs:
- onflow/atree#314
- onflow/atree#316
- onflow/atree#318
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change changes to API that can break programs using Atree's API improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OrderedMap.Get() should return Value instead of Storable
2 participants