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

Optimise merge registers for migrations - Revert of Revert #5613

Merged
merged 19 commits into from
Apr 18, 2024

Conversation

janezpodhostnik
Copy link
Contributor

@janezpodhostnik janezpodhostnik commented Apr 2, 2024

This reverts commit 7503026.

This adds a fix for flakey tests.

I called the two snapshot types:

  • mapBased (better when only reading or when expected changes are a large portion of all registers)
  • indexMapBase (better when changed registers are a smaller portion of all registers)

@janezpodhostnik janezpodhostnik requested review from SupunS, fxamacker and a team April 2, 2024 14:26
@janezpodhostnik janezpodhostnik self-assigned this Apr 2, 2024
@janezpodhostnik janezpodhostnik marked this pull request as draft April 2, 2024 14:26
@codecov-commenter
Copy link

codecov-commenter commented Apr 2, 2024

Codecov Report

Attention: Patch coverage is 3.82166% with 151 lines in your changes are missing coverage. Please review.

Project coverage is 55.85%. Comparing base (11040f7) to head (bce5dc5).

Files Patch % Lines
cmd/util/ledger/util/payload_snapshot.go 0.00% 140 Missing ⚠️
cmd/util/ledger/util/util.go 0.00% 7 Missing ⚠️
...util/ledger/migrations/atree_register_migration.go 25.00% 3 Missing ⚠️
...til/ledger/migrations/account_storage_migration.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##           feature/stable-cadence    #5613      +/-   ##
==========================================================
- Coverage                   55.89%   55.85%   -0.05%     
==========================================================
  Files                        1049     1049              
  Lines                      103232   103305      +73     
==========================================================
- Hits                        57706    57696      -10     
- Misses                      41132    41219      +87     
+ Partials                     4394     4390       -4     
Flag Coverage Δ
unittests 55.85% <3.82%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

joshuahannan and others added 9 commits April 9, 2024 15:24
Currently, storage health check always fails with
"slabs not referenced from account storage" because storage
maps are not loaded in Cadence runtime storage even though
payloads are loaded.

This commit fixes this problem by loading storage map explicitly
after loading payloads in storage.
@janezpodhostnik janezpodhostnik marked this pull request as ready for review April 9, 2024 13:37
@janezpodhostnik janezpodhostnik force-pushed the janez/index-map-based-payload branch from 5632f10 to e7a6377 Compare April 9, 2024 14:38
@turbolent
Copy link
Member

@janezpodhostnik Awesome work! What was the problem with the old, reverted variant, and what is the fix for it in this PR?

@janezpodhostnik
Copy link
Contributor Author

What was the problem with the old, reverted variant

The registers loaded in the test (from emulator) were not unique. So creating the mapping in a different order created different test results.
This was fixed by sorting the registers descending by their block height when they were edited and only taking the first encountered register for each key.

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!

Should this also be on master?

Might be good to get more eyes on it. Also, it would be great to test this exhaustively with the race detector on.

@janezpodhostnik
Copy link
Contributor Author

@turbolent this is only for migrations so it does not need to be ported back to master.

I will test it with the race detector!

@turbolent
Copy link
Member

@janezpodhostnik right, I assumed we wanted to also use it in the atree register inlining migration?

@janezpodhostnik
Copy link
Contributor Author

janezpodhostnik commented Apr 15, 2024

Actually no. This optimisation is relevant for the cases where the amount of changed registers is a smaller portion of all the registers in a snapshot. If used in the atree migration it makes it worse.

@janezpodhostnik
Copy link
Contributor Author

Tested this with the race detector on, and looks good.

Copy link
Member

@fxamacker fxamacker 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 left some comments.

cmd/util/ledger/util/snapshot/payload_snapshot.go Outdated Show resolved Hide resolved
Comment on lines 150 to 153
type IndexMapSnapshot struct {
reverseMap map[flow.RegisterID]int
payloads []*ledger.Payload
}
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to unexport IndexMapSnapshot, since mapSnapshot isn't exported?

cmd/util/ledger/util/snapshot/payload_snapshot.go Outdated Show resolved Hide resolved
cmd/util/ledger/migrations/cadence_value_diff_test.go Outdated Show resolved Hide resolved
cmd/util/ledger/migrations/migrator_runtime.go Outdated Show resolved Hide resolved
Comment on lines 19 to 22
MapBased MigrationSnapshotType = iota
// IndexMapBased is more efficient when the number of payloads that are going to change is small
// compared to the total number of payloads (less than 30% of the current number of payloads).
IndexMapBased
Copy link
Member

Choose a reason for hiding this comment

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

nit: MapBased and IndexMapBased can be confusing to differentiate without reading comments. Maybe we can rename them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't have any good ideas I renamed them according to suggested usage. Let me know what you think.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like this to help user to choose the snapshot type (without implementation detail):

  • ReadOnlySnapshotType
  • LargeChangeSetSnapshotType
  • SmallChangeSetSnapshotType

Both ReadOnlySnapshotType and LargeChangeSetSnapshotType create MapBased snapshot.

SmallChangeSetSnapshotType creates IndexMapBased snapshot.

This just an idea, so please feel free to choose any name you prefer.

@janezpodhostnik janezpodhostnik force-pushed the janez/index-map-based-payload branch from f5b20c5 to 7295f3f Compare April 17, 2024 18:43
@turbolent
Copy link
Member

@janezpodhostnik Sorry about all the conflicts, I didn't realize we were touching a lot of the same code. Happy to help with resolving the conflicts if you want to!

@janezpodhostnik
Copy link
Contributor Author

Oh, no :)
I just fixed some.

Its ok I think its not that bad.

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! Mainly reviewed the changes to the existing code

@turbolent turbolent requested a review from a team April 17, 2024 20:08
Copy link
Member

@fxamacker fxamacker 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! 👍

@janezpodhostnik janezpodhostnik merged commit a36bb74 into feature/stable-cadence Apr 18, 2024
55 checks passed
@janezpodhostnik janezpodhostnik deleted the janez/index-map-based-payload branch April 18, 2024 13:14
fxamacker added a commit that referenced this pull request Apr 23, 2024
This function was added in PR #5613 by Janez for
feature/stable-cadence and was copied into PR #5765.

Co-authored-by: Janez Podhostnik <67895329+janezpodhostnik@users.noreply.github.com>
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.

7 participants