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 backup performance with Crypto V2 #1641

Merged
merged 1 commit into from
Nov 24, 2022
Merged

Fix backup performance with Crypto V2 #1641

merged 1 commit into from
Nov 24, 2022

Conversation

Anderas
Copy link
Contributor

@Anderas Anderas commented Nov 22, 2022

The check to see whether we have any keys to backup relies on getting the actual count of total vs backed-up keys. For large accounts this rust method is very compute intensive and blocks the main thread. This has to be improved on the rust side, but for the time being we will return a cached count synchronously and then compute the actual count on a separate thread asynchronously. This will free up the main thread.

Additionally and unrelatedly I noticed that space graph computation during sync also blocks the main thread (once again for large accounts). This is due to an innocent looking MXRoom.isDirect method that actually has O(n) performance. Instead of being a state property, it is a computed property that iterates through all direct rooms to determine if itself is direct or not. Changing the performance of this method is a rabbit hole I don't want to get into. Luckily the solution is quite simple, given that MXSpaceService can use an existing MXSession.directRooms method to get all of the ids at once, instead of doing essentially O(n^2) work (for every room, check every other direct room).

@Anderas Anderas requested review from a team and Velin92 and removed request for a team November 22, 2022 13:24
@codecov
Copy link

codecov bot commented Nov 22, 2022

Codecov Report

Base: 16.03% // Head: 36.15% // Increases project coverage by +20.12% 🎉

Coverage data is based on head (3cfc84d) compared to base (5131019).
Patch coverage: 7.40% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #1641       +/-   ##
============================================
+ Coverage    16.03%   36.15%   +20.12%     
============================================
  Files          583      583               
  Lines        92561    92578       +17     
  Branches     39042    40248     +1206     
============================================
+ Hits         14840    33474    +18634     
+ Misses       77234    58099    -19135     
- Partials       487     1005      +518     
Impacted Files Coverage Δ
...trixSDK/Crypto/CryptoMachine/MXCryptoMachine.swift 0.00% <0.00%> (ø)
MatrixSDK/Data/MXRoom.m 38.31% <ø> (+36.63%) ⬆️
MatrixSDK/Space/MXSpaceService.swift 41.40% <100.00%> (+31.43%) ⬆️
...o/Algorithms/RoomEvent/MXRoomEventDecryption.swift 57.07% <0.00%> (-0.59%) ⬇️
MatrixSDK/Utils/Media/MXMediaManager.m 1.88% <0.00%> (+0.47%) ⬆️
MatrixSDK/Contrib/Swift/MXRestClient.swift 2.32% <0.00%> (+0.77%) ⬆️
...gations/LocationSharing/MXBeaconAggregations.swift 4.44% <0.00%> (+1.26%) ⬆️
MatrixSDKTests/MXBackgroundSyncServiceTests.swift 1.84% <0.00%> (+1.84%) ⬆️
MatrixSDK/Contrib/Swift/MXSession.swift 14.38% <0.00%> (+2.05%) ⬆️
MatrixSDK/Crypto/Recovery/MXRecoveryService.m 2.33% <0.00%> (+2.33%) ⬆️
... and 181 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@Velin92 Velin92 left a comment

Choose a reason for hiding this comment

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

LGTM but I see one integration test failing.

@Anderas
Copy link
Contributor Author

Anderas commented Nov 24, 2022

LGTM but I see one integration test failing.

Yea our flaky integration tests 😞. Confirmed that failing tests pass locally

@Anderas Anderas merged commit 084a06a into develop Nov 24, 2022
@Anderas Anderas deleted the andy/backup_perf branch November 24, 2022 16:36
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.

None yet

2 participants