KRTirtho / spotube

🎧 Open source Spotify client that doesn't require Premium nor uses Electron! Available for both desktop & mobile!
https://spotube.krtirtho.dev/
Other
30.41k stars 1.25k forks source link

Performance issue: Too high CPU usage #507

Closed systemoperator closed 1 year ago

systemoperator commented 1 year ago

Is there an existing issue for this?

Current Behavior

When starting Spotube without playing music, it permanently consumes 80 to 86% CPU. When playing music, it permanently consumes 80 to 107% CPU.

Expected Behavior

Much less CPU usage.

Steps to reproduce

  1. open app.
  2. optionally, play music.

Operating System

Linux Debian 11, 64-bit, Mate desktop

Spotube version

2.7.1

Installation source

Flathub (Flatpak)

Additional information

No response

karniv00l commented 1 year ago

Just my 2 cents - it clearly re-renders when it shouldn't, there's almost nothing in the UI, and still it uses a substantial amount of CPU and GPU. Should be both 0.0 when idle.

Screenshot 2023-05-08 at 14 04 45
megamorf commented 1 year ago

I can confirm this is also affecting me - M1 MacBook Pro. Energy consumption of the program far exceeds everything else on the system (2nd column = energy demand): image

spotube.log

KRTirtho commented 1 year ago

That's been fixed already. Check out the nightly release?

karniv00l commented 1 year ago

@KRTirtho still an issue on https://github.com/KRTirtho/spotube/commit/e560adee4f149450558fe910f64224fcbacd91a4

I've removed all the widgets in the player_controls.dart and narrowed it down to this line: https://github.com/KRTirtho/spotube/blob/master/lib/components/player/player_controls.dart#L51

but, that's without anything rendered, so there's still an issue with the current widget tree

RaptaG commented 1 year ago

Using 3.0.0 from Flathub on Fedora Kinoite 38, I cannot reproduce such a high CPU usage

KRTirtho commented 1 year ago

Even RepaintBoundary doesn't fix it :thinking: But bufferingStream is a empty stream. It's there for compatibility reasons only https://github.com/KRTirtho/spotube/blob/master/lib/services/audio_player/audio_players_streams_mixin.dart#L92-L104

dimitris-personal commented 1 year ago

I can reproduce here, v3.0.0 on Fedora 38/GNOME/Wayland/flathub.

Without any song playing:

Screenshot from 2023-07-12 08-41-42

Playit3110 commented 1 year ago

Under Win10 with Spotube v3.0.0 it is the same grafik

I think its some memory leak as well. Dont know if you keep all data after playing a song or if it is removed from ram and maybe stored in storage, but this is ridiculous.

Additional info

---------- ERROR ----------
OAuth2 credentials have expired and can't be refreshed.
------- STACK TRACE -------
#0      Client.send (package:oauth2/src/client.dart:109)
#1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:93)
#2      BaseClient.get (package:http/src/base_client.dart:27)
#3      SpotifyApiBase._getImpl.<anonymous closure> (package:spotify/src/spotify_base.dart:173)
<asynchronous suspension>
#4      SpotifyApiBase._requestWrapper (package:spotify/src/spotify_base.dart:206)
<asynchronous suspension>
#5      SpotifyApiBase._getImpl (package:spotify/src/spotify_base.dart:172)
<asynchronous suspension>
#6      Pages.getPage (package:spotify/src/endpoints/endpoint_paging.dart:236)
<asynchronous suspension>

was in my log and every 3 seconds it happend again.

karniv00l commented 1 year ago

Possible fix in #606, not sure about the memory leak, though may be connected to usage of RepaintBoundry (https://github.com/KRTirtho/spotube/pull/606/files#r1280247423)

KRTirtho commented 1 year ago

I think we can safely say it's fixed now. Thanks to @karniv00l :rocket:

KRTirtho commented 1 year ago

The fix is now available on v3.0.1 Please check if it works