Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » Inserting very slow when in Block Selection mode
Inserting very slow when in Block Selection mode [message #492174] Mon, 19 October 2009 10:23 Go to next message
Stefan Thurnherr is currently offline Stefan ThurnherrFriend
Messages: 5
Registered: July 2009
Junior Member
Hi all

In our own TextEditor implementation we also support Block Selection Mode, which was added to Eclipse 3.5.

Our users use the Block Selection mode heavily, and they complain that it is very slow when inserting a character in a lot of lines (say 100 lines) at the same position.

I spent quite some time investigating this, and also found two related Eclipse bugs:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=276265
https://bugs.eclipse.org/bugs/show_bug.cgi?id=268044

However I see that the same text modifications work much faster when using either the Eclipse Text Editor or the Eclipse Java Editor, so there has to be a work-around used by the Eclipse guys...

What I got so far: I overrided TextViewer#getSelection with my own implementation, to discover that MyTextViewer#getSelection is called once per line that is currently selected. The stacktrace of those calls is as follows:

  java.lang.Thread.getStackTrace(Thread.java:1436)
    com.company.name.editor.internal.MySourceViewer.getSelection(MySourceViewer.java:126)
    org.eclipse.jface.text.source.projection.ProjectionViewer.handleVerifyEvent(ProjectionViewer.java:1254)
    org.eclipse.jface.text.TextViewer$TextVerifyListener.verifyText(TextViewer.java:433)
    org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:249)
    org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
    org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
    org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:770)
    org.eclipse.swt.custom.StyledText.modifyContent(StyledText.java:6602)
    org.eclipse.swt.custom.StyledText.sendKeyEvent(StyledText.java:7442)
    org.eclipse.swt.custom.StyledText.insertBlockSelectionText(StyledText.java:5506)
    org.eclipse.swt.custom.StyledText.doContent(StyledText.java:2408)
    org.eclipse.swt.custom.StyledText.handleKey(StyledText.java:5814)
    org.eclipse.swt.custom.StyledText.handleKeyDown(StyledText.java:5839)
    org.eclipse.swt.custom.StyledText$7.handleEvent(StyledText.java:5541)
    org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
    org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
    org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1040)
    org.eclipse.swt.widgets.Widget.sendKeyEvent(Widget.java:1036)
    org.eclipse.swt.widgets.Widget.wmChar(Widget.java:1368)
    org.eclipse.swt.widgets.Control.WM_CHAR(Control.java:4053)
    org.eclipse.swt.widgets.Canvas.WM_CHAR(Canvas.java:346)
    org.eclipse.swt.widgets.Control.windowProc(Control.java:3946)
    org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:342)
    org.eclipse.swt.widgets.Display.windowProc(Display.java:4589)
    org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
    org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2409)
    org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3471)
    org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2405)
    org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2369)
    org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2221)
    org.eclipse.ui.internal.Workbench$5.run(Workbench.java:500)
    org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:493)
    org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:113)
    org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:194)
    org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:368)
    org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:559)
    org.eclipse.equinox.launcher.Main.basicRun(Main.java:514)
    org.eclipse.equinox.launcher.Main.run(Main.java:1311)
    org.eclipse.equinox.launcher.Main.main(Main.java:1287)


Obviously, no code of mine is involved...any ideas anyone?

Thanks,
stefan.
Re: Inserting very slow when in Block Selection mode [message #492372 is a reply to message #492174] Tue, 20 October 2009 09:35 Go to previous messageGo to next message
Stefan Thurnherr is currently offline Stefan ThurnherrFriend
Messages: 5
Registered: July 2009
Junior Member
Turns out that our code suffers from a known Eclipse bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=276345

My workaround is to cache the selection in MySourceViewer, fetching it only from super.getSelection upon the first call. All subsequent calls to MySourceViewer#getSelection return the cached selection.

The cached selection gets invalidated whenever a selectionChanged event occurs. This speeded up text insertion in big block selections a lot, so that the delay is now near-constant, instead of increasing linearly with every selected line.

Hope that helps anyone hitting the same problem...

Gruäss,
stefan.

Re: Inserting very slow when in Block Selection mode [message #827989 is a reply to message #492372] Sat, 24 March 2012 03:22 Go to previous messageGo to next message
tian dafeng is currently offline tian dafengFriend
Messages: 2
Registered: March 2012
Junior Member
I have the same problem with you.
but I added the code below, it is very slow.
=====================================
MySourceViewer

public static ISelection s_selection = null;

@override
public ISelection getSelection() {
return s_selection;
}

@override
protected void selectionChanged(int offset, int length) {
super.selectionChanged(offset, length);
s_selection = super.getSelection();
}

I don't know if above code is right, can you give me some suggestion?
Thank you very much!
Re: Inserting very slow when in Block Selection mode [message #829478 is a reply to message #827989] Mon, 26 March 2012 10:49 Go to previous messageGo to next message
Stefan Thurnherr is currently offline Stefan ThurnherrFriend
Messages: 5
Registered: July 2009
Junior Member
Hi

Not working on that project anymore, so the Eclipse API might have changed since 2009. But if not, and if you'd follow my description more precisely, you could end up with the following code:

=====================================
MySourceViewer

private ISelection s_selection;
private boolean cachedSelectionValid = false;

@override
public ISelection getSelection() {
if (!cachedSelectionValid) {
s_selection = super.getSelection();
cachedSelectionValid = true;
}
return s_selection;
}

@override
protected void selectionChanged(int offset, int length) {
cachedSelectionValid = false;
super.selectionChanged(offset, length);
}

=====================================

HTH,
stefan.
Re: Inserting very slow when in Block Selection mode [message #831516 is a reply to message #829478] Thu, 29 March 2012 01:40 Go to previous message
tian dafeng is currently offline tian dafengFriend
Messages: 2
Registered: March 2012
Junior Member
About this problem, the known Eclipse bug( id=276345 ) is not fixed until now.

I will follow your codes to have a try!

Thanks you very much!


Tian Dafeng
Previous Topic:Developing a FileSystem Extension
Next Topic:creating plugin folder in eclipse plugin directory
Goto Forum:
  


Current Time: Thu Mar 28 09:44:56 GMT 2024

Powered by FUDForum. Page generated in 0.03560 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top