Bug 460621 - kcalc: high energy use due to KCalculator::resizeEvent() storm
Summary: kcalc: high energy use due to KCalculator::resizeEvent() storm
Status: REPORTED
Alias: None
Product: kcalc
Classification: Applications
Component: general (show other bugs)
Version: 22.08.2
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Evan Teran
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-10-17 19:55 UTC by Janne Grunau
Modified: 2022-10-17 20:38 UTC (History)
0 users

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


Attachments
debug patch removing the resize call in resizeEvent (899 bytes, patch)
2022-10-17 19:55 UTC, Janne Grunau
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Janne Grunau 2022-10-17 19:55:31 UTC
Created attachment 152962 [details]
debug patch removing the resize call in resizeEvent

SUMMARY
Kcalc causes high energy use on Apple Silicon devices (M1 / M2) running Linux (https://asahilinux.org/). An idle Macbook with kcalc running uses ~9 Watt, the same system uses 3-4 Watt before starting kcalc and after closing it.

This seems to be caused an endless storm of KCalculator::resizeEvent()s and resulting redraws. There appears to be a problem with resizing to the minimal size. This is possibly caused by calling QWidget::resize() from within KCalculator::resizeEvent(). The Qt documentation warns explicitly about calling ::resize() inside of ::resizeEvent(): https://doc.qt.io/qt-5/qwidget.html#size-prop . I'm not sure if this is the endless recursion warned about in the documentation. If so the event handling prevents unlimited memory use one would expect from an endless recursion.

Commenting "KCalculator::resize(minSize);" in KCalculator::resizeEvent() prevents issue but results in window 1 pixel narrower than the minimal size.

STEPS TO REPRODUCE
1. start kcalc

OBSERVED RESULT
kcalc uses between 65% (kcalc window is on-screen) and 80% (kcalc window is behind) of a single CPU core 


EXPECTED RESULT
kcalc uses almost no CPU when idle

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: AsahiLinux (Qt/KDE packages are identical to ArchLinux ARM)
(available in About System)
KDE Plasma Version: 5.25.5, 5.26.0
KDE Frameworks Version: 5.98.0, 5.99.0
Qt Version: 5.15.6

ADDITIONAL INFORMATION
System is running Plasma (X11) with modeset driver, simpledrm and llvmpipe

Running kcalc with the attached kcalc_resize_debug.diff results in following output:
| resizeEvent: actual: 490x396 min: 490x396 old: 4294967295x4294967295
| resizeEvent: actual: 489x396 min: 490x396 old: 490x396
Comment 1 Janne Grunau 2022-10-17 20:38:19 UTC
This issue is not reproducible under Plasma (Wayland) on the same system with the same binaries.