-
Notifications
You must be signed in to change notification settings - Fork 137
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
[Account Storage Maps] Reduce storage register reads when using StorageFormatV2Enabled
#3683
Conversation
Currently, all domain registers are being read for a scenario that does not require it. When StorageFormatV2 feature flag is enabled, Storage.GetDomainStorageMap() reads all domain registers to determine if account is new account or in V1 format. These register reads are unnecessary for V1 accounts when: - the given domain register exists, or - the given domain register doesn't exist and createIfNotExists param is false. This commit modifies Storage.GetDomainStorageMap() to read the given domain register first (before iterating all domain registers) to reduce register reads. - If the given domain register exists, then account format is V1 and no more register reading is needed. - If the given domain register doesn't exist and createIfNotExists is false, then nil domain storage map is returned and no more register reading is needed. - Otherwise, account format (V1 account or new account) is determined by iterating all domain registers.
This commit adds tests for register reads from GetStorageMap() for account storage format v1 and v2.
Cadence Benchstat comparisonThis branch with compared with the base branch onflow:feature/combine-domain-payloads-and-domain-storage-maps commit 157d322 Collapsed results for better readability
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work improving this!
The changes look good, I left some very minor suggestions.
I'm having a bit of a harder time understanding when/where we have unnecessary register reads currently, and how the changes of the PR remove the unnecessary register reads, especially because it seems to add an additional read in one of the existing tests.
Could we maybe add a test case to feature/combine-domain-payloads-and-domain-storage-maps
before this PR that demonstrates the inefficiency (unnecessary reads), and then this PR could would show more clearly how the unnecessary read(s) are removed?
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.
StorageFormatV2Enabled
StorageFormatV2Enabled
…' into fxamacker/reduce-register-reads-for-new-accounts
@turbolent there were some questions related to Also, the updated storage_tests.go shows the reduced register reads ( PTAL. 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! The optimization of reducing the register reads is really clearly evident in the tests now, well done 👏
5646c24
into
feature/combine-domain-payloads-and-domain-storage-maps
Updates #3584
Currently in PR #3678, all domain registers are being read for a scenario that does not require it. This PR reduces register reads as discussed.
Problem
In some cases, we can reduce 10 register reads to only 2 register reads. 🚀
When
StorageFormatV2
feature flag is enabled,Storage.GetDomainStorageMap()
reads all domain registers to determine if account is new account or in v1 format.These register reads are unnecessary when:
createIfNotExists
param is false.Solution
This PR modifies
Storage.GetDomainStorageMap()
to read the given domain register first (before iterating all domain registers) to reduce register reads.If the given domain register exists, then account format is v1 and no more register reading is needed.
If the given domain register doesn't exist and
createIfNotExists
is false, thennil
domain storage map is returned and no more register reading is needed.Otherwise, account format (v1 account or new account) is determined by iterating all domain registers.
Reduced Reads
When using StorageFormatV2Enabled:
For new accounts (neither v1 or v2 yet):
For v1 accounts:
Caveat
This change increases code complexity in order to avoid reading all domain registers for this scenario. I added more comments to offset some of this tradeoff. For more context, see comment thread at #3678.
UPDATE:
I can add more tests for register reading after sync with Cadence team about this approach.I added more tests in case we don't get chance to sync with Cadence team this week.
master
branchFiles changed
in the Github PR explorer