BLeeEZ / amperfy

Amperfy is an iOS/iPadOS/macOS app to play songs from an Ampache or Subsonic server
GNU General Public License v3.0
458 stars 37 forks source link

Sluggish performance in 1.2.1 #268

Closed Jaffex closed 3 months ago

Jaffex commented 3 months ago

The performance of the app has degraded rapidly in 1.2.1(2).

Scrolling through playslist, songs or any other list is very laggy, to the point of me not being able to scroll to a desired song.

Pressing play, pause, skip or previous has quite some delay as well.

Tested on an iPhone 12 mini.

BLeeEZ commented 3 months ago

Have you tried completely closing Amperfy? It seems like some process in the background is going wild. This would explain the enormous battery drain too. I can’t reproduce this behavior currently on my side.

Jaffex commented 3 months ago

This was very weird.

I just recorded a video of how sluggish everything was, even after restarting the app.

I got some footage which is too big for here though, where you could see me tapping on control elements and the action happening seconds later but in the middle of that, the app crashed, I restarted it and then the issues seemed to be gone.

Really weird.

But seems to be working now?

Jaffex commented 3 months ago

Today I noticed that not my whole library was cached in amperfy (which it was before the update).

During the initial migration process to the new cache, the app also crashed a few times (I sent logs of that via the apple crash reporter).

I went to the settings app and noticed that the app takes up almost double the amount of space from before the update.

Maybe it was the migration process that made this sluggish and battery drainy?

Maybe since it crashed, it also left the songs both in the new and old cache?

Is that a possibility?

Jaffex commented 3 months ago

I tried deleting the entire cache of songs now, but after that, amperfy still had 22GB of size in the settings app.

I decided to delete the entire app and reinstall it (again version 1.2.1) and then download the entire library again.

After adding my server I tried downloading the entire library via amperfy settings, but after a few songs, the app crashed.

After reopening the app, the download seemed to continue for a fee more songs, but then crashed again.

I sent a crash report on both occurances via the apple crash reporter.

While downloading and before the crash, my phone also got quite warm as described in #267.

BLeeEZ commented 3 months ago

Thank you for detailed feedback. There are multiple things that need to be fixed:

  1. After the cache update it must be ensured that the database contains no binary data anymore.
  2. Even if this failed a press on "Delete downloaded Songs and Podcast Episodes" must delete all remaining binary data.
  3. When doing the cache update the download manager needs to be stopped/paused.
  4. Something is wrong with the download manager.

I looked at your crash report and it looks really really wired. I have now idea how but at some point your database broke. But after the second start it was able to get loaded.

BLeeEZ commented 3 months ago

Another interesting thing is that it seems that you are currently the only one how encountered a crash during cache update. At least TestFlight is meaning only one other crash which is not related to that. Nevertheless I investigate on the points mentioned above.

BLeeEZ commented 3 months ago

I fixed some things in 4ef3593aa651f74888ecd98d9cc59dbac12b8aef. This ensures (1.) and (3.). (2.) is already active in the beta. So when you pressed clear cache the size should have been reduced. Only artworks remain in the cache and I can't image that they take up 22GB. I have no idea why this behaved in that way on your device. (4.) requires some more investigation.

What is your server application: Ampache, Navidrom, Subsonic, ...?

Jaffex commented 3 months ago

Hey thanks for your quick reactions - my server is a navidrome server and it's running version 0.52.5.

Sadly I think I won't be able to produce any more logs about the cache update as I deleted and reinstalled amperfy entirely.

Can still provide logs about downloading the library as currently, whenever I start amperfy shortly after it will crash because it still tries to download it.

BLeeEZ commented 3 months ago

Is this bug still occurring? Is it always crashing when you open Amperfy?

Jaffex commented 3 months ago

Yes, as soon as I open amperfy it just hangs and a bit later the crash reporter appears to tell me it crashed.

I've just sent you another one a few minutes ago.

I'll try to delete and reinstall the app, wait for the background song sync and the try streaming and then try downloading my library again.

I'll report back about my findings.

BLeeEZ commented 3 months ago

Thank you for the information. I received your crash report. The problem is that Amperfy crashed without a stack trace. So I only received device info. This occurs for some crashes and I have absolutely no idea why sometimes there is a stack trace and sometimes there is none.

BLeeEZ commented 3 months ago

I think I found the bug in the download manager. At some time after the download the complete song/podcast episode gets loaded into memory. So when the file is larger then your iPhones RAM we have an overflow and the App crashes. Since this is done in iOS background callback no stack trace is available. I don't have that big songs/podcast episode in my library and my iPhone 12 Pro Max has a lot of RAM. With that setup I didn't encountered this bug. I will fix that and create soon a new beta. You can use Amperfy by following this: uninstall and install Amperfy again and then avoid downloading this big files until I create a new beta.

BLeeEZ commented 3 months ago

Download bug is fixed in 7589dc29e0481a07882fd23af986beb4d5cbd5f7.

BLeeEZ commented 3 months ago

In the newest beta you should be able to download your complete library again.

Jaffex commented 3 months ago

Downloaded my entire library over night - no hangups or sluggishness noticeable and everything is available now.

Thank you a lot!

BLeeEZ commented 3 months ago

I am happy to hear 😀.

Jaffex commented 3 months ago

I'm soorrryyy, I'm back and I think I'm still having some issues.

So the downloader worked great, I don't think there's any more issues with that, but right now I'm feeling more of the sluggishness that happened when I first opened the issue.

So basically all my songs are cached. Interacting with the app seems fine as long as I don't enter my playlists.

Performance seems okay as long as I select music via the inbuilt sections (Artists, Songs, Albums, etc.). There, everything feels normal performance wise.

But as soon as I enter the playlists, or try to play from the playlists, the app has considerable lag, selected music starts multiple seconds after clicking on it and eventually, the app crashes (just sent a few crash reports as well)

What I also noticed is that for some playlists, the wrong song count gets shown initially (by a factor, so it would be twice or three times as big as it really is and when entering the playlist, the same song appears 3 times each), but that kind of solves itself after reloading the playlist via drag from top.

I do have some considerably big playlists (thousands of songs), so maybe they are a problem? Interacting with bigger playlists seems to reliably cause a crash.

The same playlists seemed to work fine in 1.2.0 though.

BLeeEZ commented 3 months ago

Puhhh, playlist performance was an issue since ever :) There is a lot going on in the background. Playlist are always considered old, so every time you enter a playlist view a fetch is done. When the playlist is big (thousands of songs) this means:

  1. A big response to download
  2. A lot of elements in the xml needs to get parsed
  3. The old playlist needs be replaced with the new data in database -> again a lot of database fetch requests and write operations

I looked at your reported crash reports but no stack trace was available. I can't reproduce the issue on my side. A memory overflow is not occurring. I double checked that. So regarding performance there are only two options. Intentionally pause the parse process to make CPU time available for the responsiveness or keep it that way and concentrate on getting the playlist parsed as soon as possible.

My general advice is to keep the playlist at a reasonable size. This makes the life easier for the server and the client.