Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 569529

Summary: [Cocoa] Link and multi-line Text hog CPU in dark theme
Product: [Eclipse Project] Platform Reporter: Alexandr Miloslavskiy <alexandr.miloslavskiy>
Component: SWTAssignee: Alexandr Miloslavskiy <alexandr.miloslavskiy>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: alexandr.miloslavskiy, lshanmug, marc.strapetz, p.beauvoir, ts-swt
Version: 4.19   
Target Milestone: 4.19 M1   
Hardware: Macintosh   
OS: Mac OS X   
See Also: https://bugs.eclipse.org/bugs/show_bug.cgi?id=540357
https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/173520
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=86f4c9a08a2c885d029db8f1d01af4248172495c
Whiteboard:
Attachments:
Description Flags
Reproducing snippet none

Description Alexandr Miloslavskiy CLA 2020-12-07 12:41:22 EST
To my understanding, this is due to Link.drawRect() that calls 'setDefaultForeground()' each time, causing an infinite loop of redraws.

Curiously, even an invisible Link will hog CPU.
Comment 1 Alexandr Miloslavskiy CLA 2020-12-07 13:28:12 EST
Created attachment 284985 [details]
Reproducing snippet
Comment 2 Alexandr Miloslavskiy CLA 2020-12-07 13:30:59 EST
Bug is also present at least on macOS 10.15. The difference is that on BigSur, even invisible links will hog CPU.

To my understanding, the problem is caused by Bug 540357.
Comment 3 Alexandr Miloslavskiy CLA 2020-12-07 17:00:21 EST
I have tried replacing Bug 540357 with 'setUsesAdaptiveColorMappingForDarkAppearance:'. Unfortunately, it also remaps colors set with 'Link.setBackground()' etc, thus causing these SWT API to have unexpected effect.
Comment 4 Phil Beauvoir CLA 2020-12-07 18:07:11 EST
I tested the snippet on Big Sur 11.0.1 with MacBook Air 2020 and dark theme. I see around 55% continual CPU usage. Running the snippet with Light theme the CPU usage is negligible.
Comment 5 Eclipse Genie CLA 2020-12-07 20:05:04 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/173520
Comment 6 Alexandr Miloslavskiy CLA 2020-12-07 20:26:27 EST
I consider the bug to be bad enough, because SWT applications will constantly slow down the computer and drain battery life. On BigSur, this even happens when the app is minimized!

I also noticed another bug, using snippet submitted with patch:
1) Click button 'Set/remove colors' for Links
2) Click button 'Enable/disable' for Links
3) Link texts are barely visible.

This is unchanged by my patch.
Comment 8 Lakshmi P Shanmugam CLA 2020-12-10 05:25:33 EST
Thanks for the fix, Alexandr!
Comment 9 Alexandr Miloslavskiy CLA 2020-12-10 09:34:54 EST
Thanks for reviewing!
Comment 10 Lakshmi P Shanmugam CLA 2021-01-05 05:53:00 EST
Verified with I20210104-1800