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

fix(ws): Slow empty address verification on address subscription #1203

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

msbrogli
Copy link
Member

@msbrogli msbrogli commented Jan 14, 2025

Motivation

The current implementation of empty addresses was too slow. It was running in O(n) where n is the number of subscribed addresses. So, the time complexity to load a wallet was O(n^2) because the check was executed for each address.

This PR reduces the time complexity to O(m) where m is the number of empty addresses. So, the load time is reduced to O(nm). Notice that m < n / gap_limit.

Acceptance Criteria

  1. Add a separate list of empty addresses.
  2. On address subscription, add empty addresses to the empty address set.
  3. Only validate the list of empty addresses if the empty address set is greater than the limit.

Checklist

  • If you are requesting a merge into master, confirm this code is production-ready and can be included in future releases as soon as it gets merged

@msbrogli msbrogli requested a review from jansegre as a code owner January 14, 2025 18:13
@msbrogli msbrogli self-assigned this Jan 14, 2025
Copy link

github-actions bot commented Jan 14, 2025

🐰 Bencher Report

Branchfix/ws-slow-empty-addr-verification
Testbedubuntu-22.04
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
minutes (m)
(Result Δ%)
Lower Boundary
minutes (m)
(Limit %)
Upper Boundary
minutes (m)
(Limit %)
sync-v2 (up to 20000 blocks)📈 view plot
🚷 view threshold
1.50
(-9.11%)
1.49
(99.02%)
1.82
(82.63%)
🐰 View full continuous benchmarking report in Bencher

@msbrogli msbrogli force-pushed the fix/ws-slow-empty-addr-verification branch from d6cc87e to 865837a Compare January 14, 2025 19:25
Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 21.42857% with 11 lines in your changes missing coverage. Please review.

Project coverage is 83.58%. Comparing base (aede16a) to head (a3bf50c).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
hathor/websocket/factory.py 15.38% 9 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1203      +/-   ##
==========================================
- Coverage   83.63%   83.58%   -0.06%     
==========================================
  Files         320      320              
  Lines       24540    24551      +11     
  Branches     3762     3764       +2     
==========================================
- Hits        20524    20520       -4     
- Misses       3255     3267      +12     
- Partials      761      764       +3     

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

@msbrogli msbrogli force-pushed the fix/ws-slow-empty-addr-verification branch from 45937c1 to a3bf50c Compare January 23, 2025 20:42
@msbrogli msbrogli merged commit a3bf50c into master Jan 23, 2025
9 checks passed
@msbrogli msbrogli deleted the fix/ws-slow-empty-addr-verification branch January 23, 2025 20:52
This was referenced Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants