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

Performance : improve time to open a room. #3186

Merged
merged 5 commits into from
Jul 17, 2024

Conversation

ganfra
Copy link
Contributor

@ganfra ganfra commented Jul 12, 2024

Content

Currently when getting a room through the client.getRoom(roomId) method, it also initialises a MatrixTimeline and automatically add the timeline listener.
This is not ok for performance as we use the method in different contexts where we don't need to listen to timeline events.

The timeline will now be subscribed only when needed. It's still hidden by the sdk, so it remains transparent for the client .

Also, rust sdk has removed his timeline cache, getting a fullRoom takes some time as we need to initialise the inner timeline. I've now added a small lruCache to keep those in memory.

Last point, the app was triggering some back pagination because of some race condition when building UI items.

Motivation and context

Closes #3179

Screenshots / GIFs

Tests

  • Open a room
  • Close the room
  • Re-open the same room
  • Repeat and everything should stay quick and memory low.

Tested devices

  • Physical
  • Emulator
  • OS version(s):

Checklist

  • Changes have been tested on an Android device or Android emulator with API 23
  • UI change has been tested on both light and dark themes
  • Accessibility has been taken into account. See https://github.com/element-hq/element-x-android/blob/develop/CONTRIBUTING.md#accessibility
  • Pull request is based on the develop branch
  • Pull request title will be used in the release note, it clearly define what will change for the user
  • Pull request includes screenshots or videos if containing UI changes
  • Pull request includes a sign off
  • You've made a self review of your PR

Copy link
Contributor

github-actions bot commented Jul 12, 2024

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/ZiLvzq

Copy link

codecov bot commented Jul 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.12%. Comparing base (61c0216) to head (f08d30b).
Report is 35 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #3186   +/-   ##
========================================
  Coverage    76.12%   76.12%           
========================================
  Files         1643     1643           
  Lines        38668    38668           
  Branches      7475     7475           
========================================
  Hits         29437    29437           
  Misses        5341     5341           
  Partials      3890     3890           

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

@ganfra ganfra marked this pull request as ready for review July 15, 2024 10:01
@ganfra ganfra requested a review from a team as a code owner July 15, 2024 10:01
@ganfra ganfra requested review from bmarty and removed request for a team July 15, 2024 10:01
@bmarty bmarty added the PR-Misc For other changes label Jul 15, 2024
@bmarty
Copy link
Member

bmarty commented Jul 15, 2024

@ganfra do you think that merging this PR can close #3179?

@frebib
Copy link
Contributor

frebib commented Jul 15, 2024

@ganfra do you think that merging this PR can close #3179?

With this PR, performance seems better, but IMHO still not close to what it should be. I don't know if EX or rust-sdk is to blame. I still see ~1s+ room opening times. For contrast, WhatsApp opens rooms instantly.

This is especially obvious when you compare to EXA builds from ~6 months ago where timeline loading was so fast that it would cause visual stuttering in the animations. Whilst the dropped frames were annoying, it's a lot less annoying than looking at that dreaded spinner

@ganfra
Copy link
Contributor Author

ganfra commented Jul 15, 2024

Currently we are in a state where the rust sdk has no cached timeline, so it's creating one each time. It'll be back later, so should be faster again.
We also have some slowness coming from using JNA (though uniffi).
And in the end we might have some overhead from kotlin codebase, like this PR is improving.

@ganfra ganfra marked this pull request as draft July 16, 2024 14:15
@ganfra ganfra marked this pull request as ready for review July 17, 2024 13:49
@ganfra ganfra changed the title Performance : subscribe to timeline items only when necessary Performance : improve time to open a room. Jul 17, 2024
@ganfra ganfra requested review from bmarty and jmartinesp July 17, 2024 13:54
Copy link
Contributor

@jmartinesp jmartinesp left a comment

Choose a reason for hiding this comment

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

I'm a bit wary about the never called RustRoomFactory.destroy(). Other than that, it seems to have improved the situation a lot!

private val mutex = Mutex()
private var isDestroyed: Boolean = false

private data class RustRoomObjects(
Copy link
Contributor

Choose a reason for hiding this comment

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

RustRoomReferences? Naming is hard, up to you.

@@ -70,30 +88,41 @@ class RustRoomFactory(
)
}

suspend fun create(roomId: RoomId): MatrixRoom? = withContext(createRoomDispatcher) {
var cachedPairOfRoom: Pair<RoomListItem, Room>?
suspend fun destroy() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this ever called? I couldn't find anything calling it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooops, it was, but I reverted some part and forgot about this one, thanks!

Comment on lines +74 to +75
oldRoom.roomListItem.close()
oldRoom.fullRoom.close()
Copy link
Contributor

Choose a reason for hiding this comment

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

Clever!

@ganfra ganfra requested a review from jmartinesp July 17, 2024 15:28
@ganfra ganfra added the Run-Maestro Starts a Maestro Cloud session to run integration tests label Jul 17, 2024
@github-actions github-actions bot removed the Run-Maestro Starts a Maestro Cloud session to run integration tests label Jul 17, 2024
Copy link

sonarcloud bot commented Jul 17, 2024

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

LGTM and tested OK, thanks!

@ganfra ganfra merged commit a198716 into develop Jul 17, 2024
30 checks passed
@ganfra ganfra deleted the feature/fga/investigate_performance_issue branch July 17, 2024 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR-Misc For other changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opening rooms is excruciatingly slow
4 participants