vitorpamplona / amethyst

Nostr client for Android
MIT License
1.16k stars 158 forks source link

[BUG] Slow Frame Rates on Scrolling and Animations #468

Open bitmage opened 1 year ago

bitmage commented 1 year ago

Describe the bug

The client is having slow frame rates for me. It doesn't seem to be the data loading, but just scrolling and animations in the UI.

To Reproduce

  1. Go to chat, Amethyst Users.
  2. Scroll.

Expected behavior

Smooth animations.

Device:

frnandu commented 1 year ago

I'm also having quite slow frame rates on a galaxy s20

vitorpamplona commented 1 year ago

The initial problem seems to be on chat. @frnandu is chat slow for you as well?

frnandu commented 1 year ago

Yes, similar as the feed.

frnandu commented 1 year ago

I've commented a bunch of components being rendered on the feed (left just one icon of reply), and still scrolling list of feed is slow and horrible UX. Phone Galaxy S20. So something is terrible wrong that even without rendering content the UI is lagging so much on a not so much old phone....will investigate further to try to find out the reason of such lagginess...

vitorpamplona commented 1 year ago

Please do. I have been staring at the code for far too long looking for any leak to the Main thread.

Old phones seem to deal with clickable regions extremely bad (2ms + for each clickable icon on the screen). I am not sure if there is a fix for it. I am also investigating memory leaks inside the AsyncImage class from Coil that seems to send images to the GPU and not delete them in some cases. This seems to happen more in old phones. So maybe there is a missing GL call (or an existing call that is not implemented in older phones) somewhere in the framework.

frnandu commented 1 year ago

On which phone(s) do you develop/test?

vitorpamplona commented 1 year ago

Pixel 6 and 7. Soon on Pixel 8.

frnandu commented 1 year ago

No lagging on pixel 6?

vitorpamplona commented 1 year ago

It seems fine. It's a 2-year-old phone and definitely not at its prime anymore. Performance feels similar to other apps.

frnandu commented 1 year ago

I'm comparing amethyst and primal code base, since theirs smooth/responsive-ness on scrolling feed/lists in my s20 is perfect. They also have images (maybe a different lib tough) and a lot of clickable regions.

Another nostr client that also has perfect smooth scrolling on my phone is https://github.com/haorendashu/nostrmo (uses flutter).

Which means IT IS possible with this hardware to have smooth scrolling.

One big difference I see in primal's code is they do not use LiveData.

Read this: https://medium.com/@rkam88/performance-issues-with-jetpack-compose-livedata-as-a-state-holder-557bbac030c9

Is it possible that using the approach of MutableStateFlow instead of LiveData would help this issue?

I'm just brainstorming ideas/possibilities to investigate, since I don't have much experience in android/kotlin/compose, but I would really like to get to the bottom of this issue and resolve it, since I see a lot of people complaining about scrolling lag on amethyst and I think people with phones older than 1-2 years are still the majority out there.

shojofigure commented 1 year ago

Only Amethyst has this problem. Primal, Snort app, Snort PWA and Plebstr have buttery smooth scrolling. Using Samsung Galaxy Note 10+. Hope this gets fixed soon, I still use Amethyst the most.