Fix backup performance with Crypto V2 #1641
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 thatMXSpaceService
can use an existingMXSession.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).