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

Create optional map key index to optimize map key iteration 🆕 #443

Open
4 tasks
fxamacker opened this issue Sep 23, 2024 · 0 comments
Open
4 tasks

Create optional map key index to optimize map key iteration 🆕 #443

fxamacker opened this issue Sep 23, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request Execution

Comments

@fxamacker
Copy link
Member

fxamacker commented Sep 23, 2024

Atree OrderedMap stores element's key and value together to reduce number of touched slabs for write ops.

However, this can be inefficient for map key iteration since both keys and values are loaded when only keys are needed.

For very large maps, interaction limits can be reached before iteration is completed. See issues:

Suggestion

As mentioned in today's Cadence Implementation Sync, I think we can resolve this by creating an optional keys-only register (map key index) for atree maps when required thresholds/conditions are satisfied.

One approach is for Atree to provide callback functions to determine if index should be created or deleted. If the caller (e.g. Cadence) provides different callback functions then those will be used instead of defaults.

We can:

  • Create index only for large atree maps.
  • Store index in its own register(s) by using atree array or map under the hood for scalability.
  • Map key iteration would use the index if it exists.
  • Deploy this feature using HCU (no spork).

Maintaining index adds overhead for both storage size and speed. Need to try to reduce this overhead.

TODO:

  • @j1010001 will find out if this is needed in Q4 2024 or later
  • @fxamacker POC
  • Look into reasonable thresholds to create map key index by examining testnet and mainnet states.
  • Understand its impact on storage size, performance, etc.
@fxamacker fxamacker added the enhancement New feature or request label Sep 23, 2024
@fxamacker fxamacker self-assigned this Sep 23, 2024
@vishalchangrani vishalchangrani changed the title Create optional map key index to optimize map key iteration Create optional map key index to optimize map key iteration 🆕 Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Execution
Projects
None yet
Development

No branches or pull requests

2 participants