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

Speedup diff-states by over 50x (6+ days -> under 3 hours) by removing old bottleneck #6107

Merged

Conversation

fxamacker
Copy link
Member

@fxamacker fxamacker commented Jun 17, 2024

Currently, diffCadenceValues() is used in diffCadenceDictionaryValue() to compare dict keys in old and new dict values. The complexity is O(n^2) where n is number of keys.

This commit removes explicit key comparisons in diffCadenceDictionaryValue() and detects not-found keys when retrieving elements for comparisons. The complexity is O(n) where n is number of keys.

Speedup for 1 account using 10 goroutines (from diff-states logs on gcp):

  • before: 1 hour 9 minutes
  • after: 1 minute 18 seconds

For best results, this PR should be used with:

When combined with PRs 6097 and 6105, this improvement allows diff-states to compare mainnet state:

  • before: manually stopped after 6+ days
  • after: finished in 2 hours 57 minutes

Speed comparisons used same vm on gcp, same mainnet files, nworkers=80, and used less than 2TB RAM.

Discussions on discord:

Currently, diffCadenceValues() is used in diffCadenceDictionaryValue()
to compare dict keys in old and new dict values.  The complexity is
O(n^2) where n is number of keys.

This commit removes explicit key comparisons in diffCadenceDictionaryValue()
and detects not-found keys when retrieving elements for comparisons.
The complexity is O(n) where n is number of keys.

Speedup for 1 account using 10 goroutines (from diff-states logs on gcp):
- before: 1 hour 9 minutes
- after:  1 minute 18 seconds
@fxamacker fxamacker requested review from a team June 17, 2024 13:25
@fxamacker fxamacker self-assigned this Jun 17, 2024
@codecov-commenter
Copy link

codecov-commenter commented Jun 17, 2024

Codecov Report

Attention: Patch coverage is 40.54054% with 22 lines in your changes missing coverage. Please review.

Project coverage is 41.75%. Comparing base (4def8fb) to head (bfb066d).

Files Patch % Lines
cmd/util/ledger/migrations/cadence_value_diff.go 40.54% 20 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6107      +/-   ##
==========================================
- Coverage   41.75%   41.75%   -0.01%     
==========================================
  Files        1971     1971              
  Lines      138753   138736      -17     
==========================================
- Hits        57937    57925      -12     
+ Misses      74807    74799       -8     
- Partials     6009     6012       +3     
Flag Coverage Δ
unittests 41.75% <40.54%> (-0.01%) ⬇️

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.

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.

👏

@turbolent turbolent added this pull request to the merge queue Jun 17, 2024
Merged via the queue into master with commit 7e79743 Jun 17, 2024
55 checks passed
@turbolent turbolent deleted the fxamacker/optimize-diff-states-util-by-refactor-bottleneck branch June 17, 2024 16: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.

4 participants