Bug 458872 - GC.drawString is 47 times slower on Mac than on Windows
Summary: GC.drawString is 47 times slower on Mac than on Windows
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.5   Edit
Hardware: Macintosh Mac OS X
: P3 blocker with 6 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-31 08:16 EST by Jacek Kolodziejczyk CLA
Modified: 2022-07-08 06:11 EDT (History)
9 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jacek Kolodziejczyk CLA 2015-01-31 08:16:19 EST
I have run a simple test multiple times:
  for (int i = 0; i < 20000; i++) {
    event.gc.drawString("0123", 0, 0, true);
  }

Both on Mac OS X 10.10.2 and Windows XP SP3.
The swt versions: 
Mac: org.eclipse.swt.cocoa.macosx.x86_64_3.103.1.v20140903-1947.jar
Windows: org.eclipse.swt.win32.win32.x86_3.7.2.v3740f.jar

The difference in time is huge, the Mac version being 47 times slower!
This makes SWT completely unusable for text drawing applications on Mac.
Comment 1 Eclipse Genie CLA 2019-11-09 14:54:27 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Christoph Laeubrich CLA 2019-11-19 00:35:25 EST
We also see performance drops on macos versions, are there any plans to investigate this?
Comment 3 Richard Fourie CLA 2020-07-21 04:31:08 EDT
I definitely notice on macOS that the performance tanks when more text is on the screen. This could potentially be the cause of it.
Comment 4 Serge Rider CLA 2020-08-16 13:21:22 EDT
The same issue here.

We need to draw hundreds of strings on screen and it is terribly slow on MacOS while it is fine on Windows or GTK.

I did some profiling.

GC.drawString and GC.textExtent are the main problems.

GC.drawText most CPU consuming calls: (~90% of time)
org.eclipse.swt.internal.cocoa.NSLayoutManager.glyphRangeForTextContainer
org.eclipse.swt.internal.cocoa.NSLayoutManager.drawGlyphsForGlyphRange 
org.eclipse.swt.graphics.GC.createString

GC.textExtent: (~90% of time)
org.eclipse.swt.internal.cocoa.NSLayoutManager.glyphRangeForTextContainer
org.eclipse.swt.internal.cocoa.NSMutableAttributedString.setAttributedString
org.eclipse.swt.graphics.GC.createString

Eventually it is so slow (especially on 4k monitors where number of GC primitives is much bigger) that in some cases it makes UI unusable (while, again, it is perfectly fine on Windows or Linux).

Possible solution is to rewrite the custom rendering component onto JavaFX/Swing and embed it in the RCP as Composite.
Or somehow reduce the number of drawString invocations.
Comment 5 Richard Fourie CLA 2021-01-29 02:21:19 EST
Has anyone picked this up?
I think this is the reason why Eclipse has basically been like a slide show on macOS for years.
Comment 6 Phil Beauvoir CLA 2021-07-17 03:47:28 EDT
How is the speed of drawing on M1 Mac?
Comment 7 Alexandr Miloslavskiy CLA 2021-07-21 15:44:30 EDT
Patch for bug 574618 may improve things. It doesn't address text speed, but it enables window contents caching everywhere. Please give it a try.
Comment 8 Richard Fourie CLA 2022-01-27 05:13:44 EST
Bumping this as performance is still terrible on 4.22 on macOS Monterey.
Comment 9 Phil Beauvoir CLA 2022-01-27 05:32:04 EST
Testing on Mac M1 vs Windows machine with i5 11th gen processor I get Windows doing a GC.drawString() about 2x as fast as Mac. Faster, for sure, but not 47x.

But it's hard to compare Apples with Oranges with different specs.

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class DrawStringTest {
    public static void main(String[] args) {
        var display = new Display();
        var shell = new Shell(display);

        shell.setText("Draw String test");

        shell.addPaintListener(event -> {
            long now = System.currentTimeMillis();
            
            for(int i = 0; i < 200000; i++) {
                event.gc.drawString("0123", 0, 0, true);
            }
            
            System.out.println(System.currentTimeMillis() - now);
        });
        
        shell.setBounds(100, 100, 200, 200);

        shell.open();

        while(!shell.isDisposed()) {
            if(!display.readAndDispatch()) display.sleep();
        }

        display.dispose();
    }
}
Comment 10 Carlos Silva CLA 2022-01-28 14:01:49 EST
I experience similar slowness issues using Macbook Pro i7 from 2015.

Java Editor: on eclipse the problem gets worse with vertical size (horizontal space does not seem to affect).

- at 20 text lines visible, the problem is barely noticeable.
- at 30 text lines visible, the problem appears but only a little annoying
- anything more than 60 lines and typing characters fast feels like a modem terminal from the 80s

The problem does not seem to be affected by resolution. Same problem happens displaying 60 lines in a small window/small font, or large font at full screen.

Output from the code posted by Phil on 2021-01-27 in multiple runs:

```
17845
18043
18642
18658
18090
```
Comment 11 Phil Beauvoir CLA 2022-01-28 14:32:53 EST
I'm getting an average of 4000 ms per run on Mac Mini M1 with Monterey. On my Windows machine I get an average of 2000 ms per run.
Comment 12 Phil Beauvoir CLA 2022-01-29 05:55:49 EST
(In reply to Phil Beauvoir from comment #11)
> I'm getting an average of 4000 ms per run on Mac Mini M1 with Monterey. On
> my Windows machine I get an average of 2000 ms per run.

Average of 16000 ms per run on MacBook Pro (13-inch, 2017) with Monterey.
Comment 13 Richard Fourie CLA 2022-07-08 06:11:38 EDT
Still an issue on Eclipse 4.24