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

Merge feature branch feature/combine-domain-payloads-and-domain-storage-maps to master branch #3700

Conversation

fxamacker
Copy link
Member

Updates #3584

This PR merges feature branch feature/combine-domain-payloads-and-domain-storage-maps to master branch since account storage v2 is behind a feature flag.

Special thanks to @turbolent 🙌 for adding feature flag, many other improvements, and PR reviews!


  • Targeted PR against master 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

fxamacker and others added 30 commits October 31, 2024 09:51
This commit:
1. Combines all domain (non-atree) payloads into
   one account (non-atree) payload per account.
2. Combines all domain (atree) storage maps into
   one account (atree) storage map per account.
3. Uses on-the-fly (OTF) migration when an
   account is modified (write ops).

Currently, accounts store data on-chain under pre-defined domains,
such as "storage".  Each domain requires domain payload
(8-byte non-atree payload) and domain storage map payload (atree payload).
Also, each payload requires ~2 mtrie nodes (~2x96 byte overhead).

New domains were added in Cadence 1.0 and domain payloads count
increased to 150 million on Sept. 4 (was 80 million pre-spork).
Nearly 25% of total payloads on-chain are 8-byte domain payloads.
Each account on mainnet has an average of ~4 domain payloads and
~4 domain storage maps.

This commit creates 1 account (non-atree) payload and 1 account
(atree) storage map per account, eliminating all domain (non-atree)
payloads and domain storage maps for that given account.

Based on preliminary estimates using Sept. 17, 2024 mainnet state,
this approach can:
- eliminate mtrie nodes: -425 million (-28.5%)
- reduce payload count: -174 million (also -28.5%)

This commit also includes on-the-fly migration so we can see
improvements to accounts that have write activity without requiring
downtime.  Given this, we won't see the full benefits/impact until
all accounts (including idle accounts) are eventually migrated
(e.g. using full migration or other means).
…ce-domain-regsiters

Combine domain payloads and provide on-the-fly migration
This commit replaces domain string, such as "storage",
"public", "private", etc. with domain enum (integer)
as the key for AccountStorageMap.

Also, this uses CBOR to store the domain integer in shortest form.

This optimization further improves storage efficiency
of domain payloads of PR 3664.
…mbine-domain-payloads

Sync `feature/combine-domain-payloads` branch with master
This commit renames function convertKeyToDomain to
convertAccountStorageMapKeyToStorageDomain.
…ount-storage-map-key

Replace domain string with enum for AccountStorageMap key
fxamacker and others added 16 commits November 25, 2024 10:38
Currently, tests for register reads only check sequence of
register reading.  However, same register can be read multiple
times and all register reads are included in the sequence.

This commit updates tests to explicitly checks unique registers
being read in addition to sequence of registers being read.
[Account Storage Maps] Add more tests for register reads for GetDomainStorageMap()
…' into fxamacker/reduce-register-reads-for-new-accounts
…for-new-accounts

[Account Storage Maps] Reduce storage register reads when using `StorageFormatV2Enabled`
…ling-return-value

[Account Storage Maps] Add return value to account migration scheduling functions
Copy link

Cadence Benchstat comparison

This branch with compared with the base branch onflow:master commit d555d17
The command for i in {1..N}; do go test ./... -run=XXX -bench=. -benchmem -shuffle=on; done was used.
Bench tests were run a total of 7 times on each branch.

Collapsed results for better readability

@turbolent turbolent requested a review from jsproz November 27, 2024 21:06
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.

Great work! 👏

@turbolent
Copy link
Member

@onflow/cadence could you please have a final look?

@turbolent turbolent merged commit 836b5cb into master Nov 28, 2024
10 of 12 checks passed
@turbolent turbolent deleted the fxamacker/merge-feature-branch-combine-domain-payloads-to-master-branch branch November 28, 2024 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants