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

Feature/bma/incr sync perf #6917

Merged
merged 11 commits into from
Aug 31, 2022
Merged

Feature/bma/incr sync perf #6917

merged 11 commits into from
Aug 31, 2022

Conversation

bmarty
Copy link
Member

@bmarty bmarty commented Aug 23, 2022

Type of change

  • Feature
  • Bugfix
  • Technical
  • Other :

Content

Improve incremental sync performance by moving some work in the background.

Motivation and context

Fix #6027

  • other changes are regarding the fetch user mechanism, which is used to keep User database up to date.
  • Also some logs have been added.
  • 13f7A9f has to be reviewed by the CryptoTeam (CC @BillCarsonFr ). This change is not strictly related to the performance issue, the work was already in BG. But I think the SDK were computing too many times the same thing.

A large incr sync is roughly passing from 70s to 8s here.

Screenshots / GIFs

Tests

  • Use the app with a big account, after a moment offline to have a big incremental sync. Observe that the progress bar is displayed a relatively short time.

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

@bmarty bmarty requested review from a team, mnaturel and BillCarsonFr and removed request for a team August 23, 2022 09:57
@bmarty bmarty mentioned this pull request Aug 23, 2022
15 tasks
@bmarty bmarty added the Z-NextRelease For issues and PRs which should be included in the NextRelease. label Aug 25, 2022
@@ -180,8 +182,14 @@ internal class RoomSummaryUpdater @Inject constructor(
roomSummaryEntity.otherMemberIds.clear()
roomSummaryEntity.otherMemberIds.addAll(otherRoomMembers)
if (roomSummaryEntity.isEncrypted && otherRoomMembers.isNotEmpty()) {
// mmm maybe we could only refresh shield instead of checking trust also?
crossSigningService.onUsersDeviceUpdate(otherRoomMembers)
if (aggregator == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I struggle to understand why using the aggregator changes something here. Seeing the implementation of onUsersDeviceUpdate, I see we only schedule a worker we should not take so much time, right?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the current code, crossSigningService.onUsersDeviceUpdate(otherRoomMembers) is called once per room.
With the new code this is called once per sync response (which can contains many rooms)

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay thanks for explaining.

import javax.inject.Inject

internal class SyncResponsePostTreatmentAggregatorHandler @Inject constructor(
private val directChatsHelper: DirectChatsHelper,
private val ephemeralTemporaryStore: RoomSyncEphemeralTemporaryStore,
private val updateUserAccountDataTask: UpdateUserAccountDataTask,
private val getProfileInfoTask: GetProfileInfoTask,
@SessionDatabase private val monarchy: Monarchy,
private val crossSigningService: DefaultCrossSigningService,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we inject the DefaultCrossSigningService instead of the interface? Should the interface DeviceListManager.UserDevicesUpdateListener be implemented by CrossSigningService instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

The arch is not really clean, we have exception for the crypto code.

Copy link
Member

@BillCarsonFr BillCarsonFr left a comment

Choose a reason for hiding this comment

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

LGTM to me.
Maybe we could just do some renaming: We could rename onUsersDeviceUpdate in CrossSigningService in checkTrustAndAffectedRoomShiels.
And this new method would be called by the aggregator when some room membership as changed, and also as a DeviceListManager listener, when the user has some changes in keys (new device, new cross signing...)

Copy link
Contributor

@mnaturel mnaturel left a comment

Choose a reason for hiding this comment

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

Could not really test if sync is faster but okay for me.

@bmarty
Copy link
Member Author

bmarty commented Aug 29, 2022

LGTM to me. Maybe we could just do some renaming: We could rename onUsersDeviceUpdate in CrossSigningService in checkTrustAndAffectedRoomShiels. And this new method would be called by the aggregator when some room membership as changed, and also as a DeviceListManager listener, when the user has some changes in keys (new device, new cross signing...)

Thanks. a8eb7d9

@bmarty bmarty enabled auto-merge August 29, 2022 13:03
@bmarty
Copy link
Member Author

bmarty commented Aug 30, 2022

The test is passing here...

image

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@bmarty
Copy link
Member Author

bmarty commented Aug 31, 2022

This is not the same test failing. This time this is:

org.matrix.android.sdk.internal.crypto.E2eeSanityTests > testBasicBackupImport[test(AVD) - 9] FAILED

I am going to merge this PR as the fixes are highly expected.

@bmarty bmarty disabled auto-merge August 31, 2022 07:06
@bmarty bmarty merged commit 456d831 into develop Aug 31, 2022
@bmarty bmarty deleted the feature/bma/incr_sync_perf branch August 31, 2022 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-NextRelease For issues and PRs which should be included in the NextRelease.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sync sometimes never finishes/is very slow
3 participants