Bug 460085 - Plasmashell constantly uses ~20% of my CPU (and GPU?) when using avif wallpapers
Summary: Plasmashell constantly uses ~20% of my CPU (and GPU?) when using avif wallpapers
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kimageformats
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.99.0
Platform: Arch Linux Linux
: NOR major
Target Milestone: ---
Assignee: Alex Merry
URL:
Keywords: regression
Depends on:
Blocks:
 
Reported: 2022-10-07 10:37 UTC by Firlaev-Hans
Modified: 2022-10-16 05:46 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.100
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Firlaev-Hans 2022-10-07 10:37:34 UTC
SUMMARY
This has been happening ever since I upgraded my Arch system to the 5.26 beta. I'm on Wayland.
The plasmashell process constantly uses around 20-ish % of my CPU according to the system monitor (the more windows are visible, the higher the CPU usage), and all video games run like poo. When I kill plasmashell, I can literally hear my fans go quieter, and games run fine again.
The only third party widget I use is "Window Title", removing it made no difference, and neither did removing the system monitor applets from my panel.

STEPS TO REPRODUCE
1. Start plasma 5.26 on Wayland
2. Look at per-process CPU usage
3. minimize and maximize some windows and keep looking at CPU usage
(4. Try playing a video game
5. Kill plasmashell
5. Keep playing the game)

OBSERVED RESULT
Plasmashell uses unusually many CPU resources. The more windows are visible, the higher the usage.
Video games run at low framerates with lots of stuttering until plasmashell is killed.

EXPECTED RESULT
Plasmashell should barely use any CPU resources. Game performance should not be impacted by plasmashell running or not.

SOFTWARE/OS VERSIONS
Operating System: Arch Linux
KDE Plasma Version: 5.25.90
KDE Frameworks Version: 5.98.0
Qt Version: 5.15.6
Kernel Version: 6.0.0-zen1-1-zen (64-bit)
Graphics Platform: Wayland
Processors: 8 × Intel® Core™ i7-7700 CPU @ 3.60GHz
Memory: 15.5 GiB of RAM
Graphics Processor: AMD Radeon RX 580 Series

ADDITIONAL INFORMATION
In case it may be relevant, I'm using two monitors.
Also, running plasmashell with mesa-git or using zink instead of RadeonSI for OpenGL made no difference.
It seems like the GPU usage is also higher (which would make sense for the game performance) but system monitor doesn't show any GPU info for me right now for some reason.
Comment 1 Fushan Wen 2022-10-10 08:06:44 UTC
Could you run

perf top -p $(pidof plasmashell) -K

to see what's hogging the CPU?
Comment 2 Firlaev-Hans 2022-10-10 09:23:46 UTC
(In reply to Fushan Wen from comment #1)
> Could you run
> 
> perf top -p $(pidof plasmashell) -K
> 
> to see what's hogging the CPU?

Unfortunately that command does not appear to work for me: 
>Error:
>Failed to mmap with 22 (Invalid argument)
Comment 3 Firlaev-Hans 2022-10-10 09:33:59 UTC
Perhaps this is useful (this is the output without specifying the PID):

>    37.99%  QSGRenderThread  libc.so.6                      
>    24.36%  plasmashell      libQt5Core.so.5.15.6           
>     8.28%  plasmashell      libglib-2.0.so.0.7400.0        
>     5.96%  plasmashell      libQt5Gui.so.5.15.6            
>     5.58%  plasmashell      libc.so.6                      
>     5.50%  plasmashell      libQt5Quick.so.5.15.6          
>     3.88%  plasmashell      [vdso]                         
>     1.13%  perf             perf                           
>     0.66%  plasmashell      ld-linux-x86-64.so.2           
>     0.53%  plasmashell      libQt5Widgets.so.5.15.6        
>     0.49%  swapper          [unknown]                      
>     0.49%  kwin_wayland     radeonsi_dri.so                
>     0.45%  plasmashell      kimg_avif.so                   
>     0.41%  Isolated Web Co  libxul.so                      
>     0.29%  plasmashell      libstdc++.so.6.0.30            
>     0.27%  perf             libc.so.6                      
>     0.24%  plasmashell      libwayland-client.so.0.21.0    
>     0.22%  plasmashell      breeze.so                      
>     0.22%  plasmashell      libQt5WaylandClient.so.5.15.6  
>     0.18%  plasmashell      libKF5XmlGui.so.5.98.0         
>     0.17%  kwin_wayland     libkwin.so.5.25.90             
>     0.15%  QSGRenderThread  radeonsi_dri.so                
>     0.15%  kwin_wayland     libc.so.6                      
>     0.14%  kwin_wayland     [unknown]                      
>     0.11%  kwin_wayland     libQt5Gui.so.5.15.6            
>     0.10%  plasmashell      libQt5Qml.so.5.15.6            
>     0.09%  kwin_wayland     libQt5Core.so.5.15.6           
>     0.08%  plasmashell      libKirigamiPlugin.so           
>     0.07%  plasmashell      libpulse-mainloop-glib.so.0.0.6
>     0.06%  plasmashell      libKF5PlasmaQuick.so.5.98.0    
>     0.06%  QSGRenderThread  libQt5Quick.so.5.15.6
Comment 4 Fushan Wen 2022-10-10 14:54:51 UTC
Thanks for the information
Comment 5 Firlaev-Hans 2022-10-14 18:26:12 UTC
I just upgraded my Arch system to the stable 5.26 release and this issue still persists.
Comment 6 Firlaev-Hans 2022-10-14 21:29:55 UTC
Okay, I did some investigation, this is the weirdest thing ever. It is apparently wallpaper related.

Since, in Bug 460248, Patrick Silva said they couldn't reproduce this on a fresh account, I tried removing stuff from plasmashellrc and the plasma*appletsrc until the problem went away.

I determined that resetting the wallpaper for my second monitor "fixed" the issue. The issue would only occur if my *second* monitor's wallpaper was an AVIF image (which it previously was). Using PNG or JPG, CPU usage was normal.
Oddly enough, setting the same AVIF wallpaper on my primary monitor did not cause the issue.

Half an hour later the two displays seemingly "switched roles", now only the first monitor would cause the issue when using an AVIF wallpaper on it, and the second one didn't. I'm not sure what caused that.

In any case, as long as I'm not using AVIF wallpapers at all, I guess I'm safe(?)
Comment 7 Fushan Wen 2022-10-14 23:30:54 UTC
Two dead loops were fixed in 5.26.1, please test again then. Thanks in advance!
Comment 8 Fushan Wen 2022-10-15 00:30:48 UTC
Unfortunately I can confirm it's not fixed
Comment 9 Bug Janitor Service 2022-10-15 00:58:15 UTC
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/2221
Comment 10 Bug Janitor Service 2022-10-15 03:42:40 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kimageformats/-/merge_requests/112
Comment 11 Bug Janitor Service 2022-10-15 06:15:47 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kimageformats/-/merge_requests/113
Comment 12 Fushan Wen 2022-10-15 09:29:01 UTC
Git commit 350ce1b990460cb2178f369f22fe80803f5645f3 by Fushan Wen.
Committed on 15/10/2022 at 06:02.
Pushed by fusionfuture into branch 'master'.

avif: return `false` in `canRead()` when `imageIndex >= imageCount`

Otherwise when `cache: false` is set in AnimatedImage, QMovie will try
to read the image forever.
FIXED-IN: 5.100

M  +5    -0    src/imageformats/avif.cpp

https://invent.kde.org/frameworks/kimageformats/commit/350ce1b990460cb2178f369f22fe80803f5645f3
Comment 13 Fushan Wen 2022-10-15 09:30:52 UTC
Git commit 1190e53e9b69da6f9663ceb75c4813c5708b7cbd by Fushan Wen.
Committed on 15/10/2022 at 06:11.
Pushed by fusionfuture into branch 'master'.

avif: always indicate endless loop

avif does not support loops but endless loop was the behavior before
460085 was fixed, so a workaround is added.

See also: https://github.com/AOMediaCodec/libavif/issues/347

M  +2    -1    src/imageformats/avif.cpp

https://invent.kde.org/frameworks/kimageformats/commit/1190e53e9b69da6f9663ceb75c4813c5708b7cbd