strawberrymusicplayer / strawberry

:strawberry: Strawberry Music Player
https://www.strawberrymusicplayer.org/
GNU General Public License v3.0
2.74k stars 191 forks source link

(macOS) Performance: constant high CPU usage #829

Closed foss- closed 1 year ago

foss- commented 3 years ago

System Information:

Constant high CPU usage on macOS.

To Reproduce With Strawberry open and doing nothing (no scrolling or playing a track or any interaction at all) Strawberry constantly sits at over 40% CPU usage

Screenshot 2021-11-13 at 17 46 43

Playing a track it sits at over 60% while sometimes spiking at over 100%:

Screenshot 2021-11-13 at 17 50 27

Expected behavior CPU usage is too high. Comparing with Apples music app which sits at 0,1% when idle and goes up to under 2% when playing a track.

Additional context Spin Dump: https://bin.disroot.org/?73b77829f80a251e#5vwiHDcJRRTccyUMsLmNgUidDriH9xRhv6HMAEW8hoUn Process Sample: https://bin.disroot.org/?103ce9f6c263e0fb#HzSkmVV7rWMBXs5GyL1nzbP6h6cA92XRhmUJc6ATSDKw

jonaski commented 2 years ago

Uses 15-20% CPU here in my macOS VM. Did you change any specific configuration options? Did you try with a fresh configuration? delete ~/Library/Preferences/org.strawberrymusicplayer.Strawberry.plist

foss- commented 2 years ago

Interesting finding and thanks for going through the effort to verify this problem. Are you also running macOS 11? I enabled storing metadata back to files and disabled the default library background picture. Other than that can't recall changes.

I removed ~/Library/Preferences/org.strawberrymusicplayer.Strawberry.plist as suggested, installed latest main build.

CPU consumption while playing a track is now back to normal levels. Will keep an eye on this and re-open if issue returns, hopefully with more details as to which change triggers the CPU increase.

foss- commented 2 years ago

Well that was a quick one. Connecting an external monitor makes CPU go up to ~50-80% playing a track and ~40-50 when ideling. For comparison: when playing a track in Apples Music app CPU is around or mostly below 2%.

jonaski commented 2 years ago

It might be related to #542

foss- commented 2 years ago

Which gladly is seeing active development and just yesterday received patch set 8. Not sure if it is indeed the cause for the constant high CPU though, as no scrolling is involved in my tests.

e471wo commented 2 years ago

duno if that help, but on my mac, if I put no analyser -> cpu down. (note -> Version 1.0.0-125-g4c6251bf)

image

richarddbarnett commented 2 years ago

I found this because Strawberry 1.0.1 on macOS 11.6.2 was consuming a lot of CPU (about 40%) when paused. Turning off the analyzer seems to fix it.

MacBook Pro 15", 2.9GHz quad-core i7. External monitor is connected via USB-C.

foss- commented 2 years ago

Also confirming: Strawberry 1.0.1-22-g56b2630a on macOS 11.6.2 sitting idle ~40% CPU Switching from Block analyzer to No analyzer and it goes to 0,0 sitting idle.

jonaski commented 2 years ago

What about the other analyzers, do they cause as much CPU too?

foss- commented 2 years ago

Strawberry idle / playing ~40% / ~60% for all analyzers.

jonaski commented 2 years ago

The problematic code is in https://raw.githubusercontent.com/strawberrymusicplayer/strawberry/master/src/analyzer/analyzerbase.cpp There is a timer that repaints every few milliseconds depending the framerate set. Although this not a problem on any other platforms and is likely a Qt-macOS specific issue.

jonaski commented 2 years ago

Can you try the latest from https://builds.strawberrymusicplayer.org/macos/ those have Qt 6.3.0 (instead of Qt 6.2.x).

foss- commented 2 years ago

macOS 12.3.1 Strawberry 1.0.4-5-g907dfee6 Playing a track with analyzer selected CPU is under 20% which is somewhat acceptable. (Apple music app is ~3% but it is optimised for macOS) Ideling it is ~12% which is high for doing ... nothing.

But since both values have improved a lot. I think it is fair to close this issue. What do you think? Can others test as well?

Calinou commented 2 years ago

It might be worth disabling the analyzer by default on macOS to fix the issue out of the box. I'm not sure how many people actually look at the analyzer anyway. Typically, you minimize the music player a few seconds after choosing a track to play :slightly_smiling_face:

jonaski commented 1 year ago

In my macOS Big Sur VM which is slow in general strawberry is using approximately 4% - 10% when idle and 15-30% when playing, both with the analyzer is on. If I turn the analyzer off when idle, the CPU goes almost to 0, when playing it's under 20%. When removing the timer that does frequent repaints when the analyzer is on, the CPU usage goes down, I also made a small test program, same thing happens with the test program, so it's not specific to the analyzer itself, but frequent repaints. I'm considering filing a bug report to Qt, but at least for me, I also see the Activity monitor having somewhat high CPU usage, so my VM is not really ideal for benchmarking since it's so much slower than a real mac would be. I don't think I can do much with this, so closing it for now. Turning off the analyzer as a solution for those having the issue is written in the Wiki: https://wiki.strawberrymusicplayer.org/wiki/Known_Issues