eclipse-platform / eclipse.platform.ui

Eclipse Platform
https://projects.eclipse.org/projects/eclipse.platform
Eclipse Public License 2.0
79 stars 168 forks source link

DefaultWordHighlightStrategy freezes UI on each text selection change for large files #861

Open sebthom opened 1 year ago

sebthom commented 1 year ago

When opening large files in the GenericEditor each mouse click or cursor move results in a freeze of several seconds making the editor unusable.

This is the stacktrace during the freeze

"main" eclipse-platform/eclipse.platform.text#1 prio=6 os_prio=0 cpu=276015.62ms elapsed=6808.45s tid=0x0000018f0ee29b80 nid=0xb2c runnable  [0x000000318e9fc000]
   java.lang.Thread.State: RUNNABLE
        at java.util.regex.Pattern$CharPropertyGreedy.match(java.base@17.0.6/Pattern.java:4300)
        at java.util.regex.Pattern$StartS.match(java.base@17.0.6/Pattern.java:3641)
        at java.util.regex.Matcher.search(java.base@17.0.6/Matcher.java:1728)
        at java.util.regex.Matcher.find(java.base@17.0.6/Matcher.java:745)
        at org.eclipse.ui.internal.genericeditor.DefaultWordHighlightStrategy.applyHighlights(DefaultWordHighlightStrategy.java:96)
        at org.eclipse.ui.internal.genericeditor.DefaultWordHighlightStrategy.lambda$0(DefaultWordHighlightStrategy.java:70)
        at org.eclipse.ui.internal.genericeditor.DefaultWordHighlightStrategy$$Lambda$13442/0x00000008012ce0b0.selectionChanged(Unknown Source)
        at org.eclipse.jface.text.TextViewer.firePostSelectionChanged(TextViewer.java:2718)
        at org.eclipse.jface.text.TextViewer.firePostSelectionChanged(TextViewer.java:2648)
        at org.eclipse.jface.text.TextViewer$2.run(TextViewer.java:2627)
        at org.eclipse.swt.widgets.Display.runTimer(Display.java:4152)
        at org.eclipse.swt.widgets.Display.messageProc(Display.java:3272)
        at org.eclipse.swt.internal.win32.OS.DispatchMessage(Native Method)
        at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3640)
        at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1155)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
        at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1046)
        at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:155)
        at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:643)
        at org.eclipse.ui.internal.Workbench$$Lambda$183/0x000000080029fa40.run(Unknown Source)
        at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
        at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:550)
        at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:171)
        at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
        at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
        at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:402)
        at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(java.base@17.0.6/Native Method)
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(java.base@17.0.6/NativeMethodAccessorImpl.java:77)
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(java.base@17.0.6/DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(java.base@17.0.6/Method.java:568)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1467)
        at org.eclipse.equinox.launcher.Main.main(Main.java:1440)

   Locked ownable synchronizers:
        - None

Here is a sample file AArch64GenAsmMatcher.cc.zip that I got from @jonahgraham

jonahgraham commented 1 year ago

@sebthom are you looking into this? The current code calculates the annotations for the whole file on each selection change, which is overwork. I think I'll be able to look at this next week if you don't have a solution before then.

sebthom commented 1 year ago

@jonahgraham I would appreciate if you can have look at it.

HeikoKlare commented 1 year ago

I have worked on a similiar issue in the Java editor (slow updates of the annotation model due to selections in large files), but did not find the time to finalize it yet and provide a PR for it. Probably the behavior and fix will be quite similar to this issue, so to avoid duplicate work I can also have a look at how the two issues and the underlying code is related and hopefully provide a combined/reusable fix.

jonahgraham commented 1 year ago

Thanks @HeikoKlare - please feel free to tag me in that issue/PR and I will follow your lead. I hadn't quite gotten to start here.

HeikoKlare commented 1 year ago

@jonahgraham Sorry for taking so long to reply.

I have taken another look at the problem I addressed and tried to relate it to this issue. I was not able to figure out yet whether both can actually be reduced to the same root cause, but at least both are related to updates of the annotation model.

I have now created a GitHub issue describing the problem I have addressed in more detail: https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/665 And I have committed the changes that I have tried out so far on a branch of my fork: https://github.com/HeikoKlare/eclipse.jdt.ui/commit/f27742ee28f232da3e88e6585467e6dc4e6295de

As far as I was able to validate, the changes so far resolve my issue. Maybe it can help you to solve this issue as well. I am not sure when I will find the time to have a deeper look at how far the issues are related and whether there is a chance for a combined fix.

jonahgraham commented 1 year ago

Thanks @HeikoKlare.