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

storage-plus: Implement u128 key #694

Merged
merged 2 commits into from
Mar 30, 2022
Merged

storage-plus: Implement u128 key #694

merged 2 commits into from
Mar 30, 2022

Conversation

orkunkl
Copy link
Contributor

@orkunkl orkunkl commented Mar 29, 2022

I needed to implement a (Uint128, &Addr) composite keymap, since u128 is not implemented for PrimaryKey I was not able to.
Not sure if u128 is intentionally not implemented here, just pushing it here in case it is left over

@orkunkl orkunkl requested a review from maurolacy March 29, 2022 13:45
Copy link
Contributor

@ueco-jb ueco-jb left a comment

Choose a reason for hiding this comment

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

since u128 is not implemented for PrimaryKey I was not able to.
Not sure if u128 is intentionally not implemented here

Yes it was. #547 (comment)
The real question is - do you really need 128 bit key?
@maurolacy ?

@orkunkl
Copy link
Contributor Author

orkunkl commented Mar 29, 2022

I building an optimized version of Claim and a sorted index that will save a sorted list of a defined number of claims.
I am using prefixed keys but saving the data to key as well.

pub total_claim_sort_index: Map<'a, (u128, &'a Addr), bool>

To achieve the sorted claim list, I am indexing the total claim amount with the address as appended key, bool is just a placeholder.

@orkunkl
Copy link
Contributor Author

orkunkl commented Mar 29, 2022

Looks like doubling the size of every key will be very costly for this feature...

@maurolacy
Copy link
Contributor

maurolacy commented Mar 29, 2022

Looks like doubling the size of every key will be very costly for this feature...

Yes. We can add this, but better to avoid it.

My question would be, why you can't use u64 for your key? (Ah, because claim amount is u128)

Converting the key to a string would work too. Or using a tuple of two u64 values. Which is somewhat clumsy, but effective.

Copy link
Contributor

@maurolacy maurolacy left a comment

Choose a reason for hiding this comment

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

On second thought, I think this wouldn't hurt, as those bytes are in memory / stack in the first place, and do not hit storage.

Approving. Will create a follow-up issue to benchmark Key performance with and without u128 support, so we confirm this.

Update: See #695.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants