oxen-io / session-android

A private messenger for Android.
https://getsession.org
GNU General Public License v3.0
1.86k stars 170 forks source link

[SES-2021] Optimise XML loading #1512

Closed simophin closed 3 months ago

simophin commented 3 months ago

Description

This PR tries to optimize some perspective of XML View loading, namely:

  1. Cache the expensive themeing operation that every View's initialization calls. (BaseActionBarActivity.getTheme()). I tested the theme changing it still works after the change.
  2. Adds a ViewPool to ConversactionActivityV2's RecyclerView.
  3. Lazy loads some views so that they only get inflated when in use
  4. Misc code tidy-up
simophin commented 3 months ago

Have tested & everything the PR touches that previously worked still appears to work, although it's difficult to quantify any performance changes without profiling.

I did notice that we're not specifying a size of the RecyclerViewPool and I believe the default max size is 5 (although I'm not seeing this 5 value referenced in modern docs - only in the first set of deprecated docs I came across). If we think of how many single line messages we can fit on a mobile device the number is probably closer to 13 - as such, would it be worth specifying that value as 13 via setMaxRecycledViews? (see: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.RecycledViewPool)

Other than that query (feel free to address as you see fit) I'm perfectly happy to approve - nice job! =D

The performance gain mainly comes from the first few enter into the conversation screen, and it's only obvious on a cheap device. I had printed out a few measurement, my Samsung used to take around 3-4 seconds to create the activity/message views and it's down to 1 second. Obviously there are still other things to do but they are much harder to do now.