Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 345093 - Shell.setVisible is extremely slow on Linux
Summary: Shell.setVisible is extremely slow on Linux
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.7   Edit
Hardware: PC Linux-GTK
: P3 major with 5 votes (vote)
Target Milestone: 3.8 M3   Edit
Assignee: Bogdan Gheorghe CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-05-09 03:15 EDT by Deepak Azad CLA
Modified: 2012-02-04 06:13 EST (History)
14 users (show)

See Also:


Attachments
Thread Dump and Screenshot of Issue (20.04 KB, text/plain)
2011-07-20 23:55 EDT, Rob Winch CLA
no flags Details
YourKit Snapshot of issue (2.01 MB, text/plain)
2011-07-20 23:57 EDT, Rob Winch CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Deepak Azad CLA 2011-05-09 03:15:25 EDT
The following snippet takes 5 seconds on windows but about 140 seconds on Linux (RHEL). Found this while working on bug 343242.
-----------------------------------------------------------------------------
package org.eclipse.swt.snippets;

import java.util.Date;

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

public class Snippet50 {

	public static void main(String[] args) {
		Display display = new Display();
		Shell shell = new Shell(display);
		shell.setText("Shell"); //$NON-NLS-1$
		shell.setSize(200, 200);
		shell.open();

		System.out.println(new Date());
		for (int i = 0; i < 1000; i++) {
			shell.setVisible(false);
			//shell.setText("shell" + i); //$NON-NLS-1$
			shell.setVisible(true);
		}
		while (display.readAndDispatch()) {
		}
		System.out.println(new Date());
		display.dispose();
	}
}
-------------------------------------------------------------------------------
Comment 1 Dani Megert CLA 2011-05-09 03:21:16 EDT
Deepak, is this a regression compared to 3.6?
Comment 2 Deepak Azad CLA 2011-05-09 04:23:22 EDT
(In reply to comment #1)
> Deepak, is this a regression compared to 3.6?

Nope, same behavior in 3.6.
Comment 3 Deepak Azad CLA 2011-05-09 05:51:06 EDT
Is it possible for Shell.setVisible(boolean) to be fast sometimes on linux ? 

I ask this because the performance test under question in bug 343242 sometimes runs very fast and sometimes runs slowly. And this behavior is observed only on RHEL, the test is consistently slow on SLED.
Comment 4 Rob Winch CLA 2011-07-20 23:52:45 EDT
I believe I am having a very similar issue on Ubuntu with Spring Tool Suite. I have logged a JIRA to them at https://issuetracker.springsource.com/browse/STS-1954 I want to be upfront that I have not had this happen with the standard Eclipse distribution, but believe that I am having the same issue.

For your convenience I have copied what I believe to be the relevant information to this bug. Please let me know if I can be of further assistance in getting this issue resolved.

At times using the Code Suggest will cause Eclipse to hang for what appears to be an indefinite amount of time (I know at one point it lasted at least 19 min). This cause Eclipse to freeze, the suggest box will not go away (even when bringing Firefox or other applications to focus), and near 100% CPU usage.

I have taken a thread dump and obtained a YourKit snapshot with CPU profiling enabled. The results of which imply that the native call to _g_main_context_iteration(Native Method) triggered by Shell.setVisible is responsible.

Below you can find some information about my environment:

$ java -version
java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) Server VM (build 19.1-b02, mixed mode)
$ uname -a
Linux rwinch 2.6.38-8-generic-pae #42-Ubuntu SMP Mon Apr 11 05:17:09 UTC 2011 i686 i686 i386 GNU/Linux

If there is anything else I can do to be of assistance, please let me know.

Regards,
Rob
Comment 5 Rob Winch CLA 2011-07-20 23:55:39 EDT
Created attachment 200047 [details]
Thread Dump and Screenshot of Issue

Attached zip of Thread Dump and Screenshot of Issue
Comment 6 Rob Winch CLA 2011-07-20 23:57:43 EDT
Created attachment 200048 [details]
YourKit Snapshot of issue

Attached YourKit Snapshot of the issue
Comment 7 Steffen Pingel CLA 2011-07-26 12:52:01 EDT
I have seen the same problem with Eclipse SDK I20110719-0800 on Ubuntu 11.04 when invoking content assist. The UI thread stalls in native code for a considerable time before the popup becomes visible.
Comment 8 Felipe Heidrich CLA 2011-07-26 14:13:10 EDT
Arun, please investigate.
Comment 9 Aaron Digulla CLA 2011-07-27 08:10:40 EDT
Possibly related: bug 353101 - "SWTException: Widget is disposed" when right clicking in Java editor window
Comment 10 Aaron Digulla CLA 2011-07-27 08:33:48 EDT
Which version of Gtk is this? I have

gtk2-engines-qtcurve  1.8.5-1
gvfs  1.8.0-0ubuntu2
libasound2  1.0.24.1-0ubuntu5
libaspell15  0.60.6-6
libatk1.0-0  2.0.0-0ubuntu1
libc6  2.13-0ubuntu13
libcairo2  1.10.2-2ubuntu2
libcanberra0  0.28-0ubuntu3
libcanberra-gtk0  0.28-0ubuntu3
libcanberra-gtk-module  0.28-0ubuntu3
libenchant1c2a  1.6.0-2
libfontconfig1  2.8.0-2.1ubuntu3
libfreetype6  2.4.4-1ubuntu2
libgail18  2.24.4-0ubuntu2
libgdk-pixbuf2.0-0  2.23.3-0ubuntu1
libglib2.0-0  2.28.6-0ubuntu1
libgstreamer0.10-0  0.10.32-3ubuntu3.1
libgstreamer-plugins-base0.10-0  0.10.32-1ubuntu5
libgtk2.0-0  2.24.4-0ubuntu2
libgvfscommon0  1.8.0-0ubuntu2
libhunspell-1.2-0  1.2.14-4
libice6  2
libicu44  4.4.2-2
libjpeg62  6b1-1ubuntu1
libltdl7  2.2.6b-2ubuntu3
libnspr4  4.8.7-0ubuntu1
libnss3  3.12.9+ckbi-1.82-0ubuntu2
libogg0  1.2.0~dfsg-1
libpango1.0-0  1.28.4-0ubuntu1
libpixman-1-0  0.20.2-0ubuntu1
libsm6  2
libsoup2.4-1  2.34.0-0ubuntu1
libsqlite3-0  3.7.4-2ubuntu5
libstartup-notification0  0.10-1build1
libstdc++6  4.5.2-8ubuntu4
libtdb1  1.2.9-1fakesync1
libvorbis0a  1.3.2-1ubuntu1
libvorbisfile3  1.3.2-1ubuntu1
libwebkitgtk-1.0-0  1.3.13-0ubuntu2
libx11-6  2
libxau6  1
libxcb1  1.7-2ubuntu2
libxcb-atom1  0.3.6-1build1
libxcb-aux0  0.3.6-1build1
libxcb-event1  0.3.6-1build1
libxcb-render0  1.7-2ubuntu2
libxcb-shm0  1.7-2ubuntu2
libxcomposite1  1
libxcursor1  1
libxdamage1  1
libxdmcp6  1
libxext6  2
libxfixes3  1
libxi6  2
libxinerama1  2
libxml2  2.7.8.dfsg-2ubuntu0.1
libxrandr2  2
libxrender1  1
libxslt1.1  1.1.26-6build1
libxt6  1
libxtst6  2
xulrunner-1.9.2  1.9.2.18+build2+nobinonly-0ubuntu0.10.10.1
Comment 11 Steffen Pingel CLA 2011-07-27 09:51:33 EDT
I have these versions:

ii  libgtk2.0-0                 2.24.4-0ubuntu2             The GTK+ graphical user interface library
ii  libgtk2.0-bin               2.24.4-0ubuntu2             The programs for the GTK+ graphical user interface library
ii  libgtk2.0-cil               2.12.10-1ubuntu1            CLI binding for the GTK+ toolkit 2.12
ii  libgtk2.0-common            2.24.4-0ubuntu2             Common files for the GTK+ graphical user interface library
Comment 12 Rob Winch CLA 2011-07-27 21:33:02 EDT
I have the following versions installed:

libgtk2.0-0
libgtk2.0-bin
libgtk2.0-cil
libgtk2.0-common
libgtk2.0-dev

PS: I noticed that Aaron has xulrunner installed. When I first posted to this issue I was using webkit. I have since (on 7-27) switched to xulrunner and at times have observed some slugishness when using the content assist. However, since then I have not experienced the IDE completely locking up due to setVisible consuming the CPU. This very well could be coincidental, but I thought I would post on here just in case it was beneficial.
Comment 13 Aaron Digulla CLA 2011-07-28 04:19:56 EDT
(In reply to comment #12)
> I have the following versions installed:
> 
> libgtk2.0-0
> libgtk2.0-bin
> libgtk2.0-cil
> libgtk2.0-common
> libgtk2.0-dev

Please use "dpkg --status" with the package name to determine the version of the library.

> PS: I noticed that Aaron has xulrunner installed. When I first posted to this
> issue I was using webkit. I have since (on 7-27) switched to xulrunner and at
> times have observed some slugishness when using the content assist. However,
> since then I have not experienced the IDE completely locking up due to
> setVisible consuming the CPU. This very well could be coincidental, but I
> thought I would post on here just in case it was beneficial.

I also have libwebkitgtk loaded. I'm not sure how to switch between the two.
Comment 14 Rob Winch CLA 2011-07-28 09:21:09 EDT
> (In reply to comment #12)
> Please use "dpkg --status" with the package name to determine the version of
> the library.

Apologies for my carelessness.

libgtk2.0-0      2.24.4-0ubuntu2
libgtk2.0-bin    2.24.4-0ubuntu2
libgtk2.0-cil    2.12.10-1ubuntu1
libgtk2.0-common 2.24.4-0ubuntu2
libgtk2.0-dev    2.24.4-0ubuntu2

> I also have libwebkitgtk loaded. I'm not sure how to switch between the two.

You can determine which is being used by following the instructions on the FAQ [1]. There is also a FAQ for how to run using WebKit [2] and Mozilla [3]. For me using Mozilla involved installing the latest 1.x xulrunner (2.x will not work with Eclipse).

To be honest, I do not know much about how Eclipse works behind the scenes. The reason I tried this was because a while back I had an issue where Eclipse content assist did not work with xulrunner 2.x and I was able to fix it by explicitly setting the version. I thought I would try to explicitly set the version again and came upon the fact that I was using WebKit. My guess is that xulrunner was removed since Firefox now uses an internal xulrunner which meant I had been using WebKit. Explicitly installing xulrunner switched me over. To emphasize, I really do not know if this is even on the right track. I'm really just taking a stab in the dark with this.

[1] http://www.eclipse.org/swt/faq.php#printmozillapath
[2] http://www.eclipse.org/swt/faq.php#browserwebkitgtk
[3] http://www.eclipse.org/swt/faq.php#howusemozilla
Comment 15 Rob Winch CLA 2011-08-08 18:03:06 EDT
I just experienced the same issue with Mozilla XULRunner 1.9.2.17 - 20110424120753 that I was having when using WebKit. This implies that switching to WebKit does not prevent eclipse from totally locking up (in this instance I waited 15 min before killing the process). I gathered a thread dump along with a YourKit snapshot, but they look pretty much the same as last time. If you would like I can post them though.
Comment 16 Deepak Azad CLA 2011-08-08 21:44:04 EDT
Bumping up the severity, as Shell.setVisible is used frequently and a number of people have experienced the problem now.
Comment 17 Julek Kopczewski CLA 2011-09-19 12:33:10 EDT
I've experienced a similar bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=358037

Don't know if this is the same issue, but it's incredibly annoying, had to switch from using Eclipse altogether.
Comment 18 Charles O'Farrell CLA 2011-10-01 19:56:34 EDT
A duplicate bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=349287

Not to complain, but I see this bug every day without fail. :(

Please let me know if there is anything I can do to help.
Comment 19 Charles O'Farrell CLA 2011-10-01 20:03:35 EDT
I should add for completeness that this started happening when I switched from Ubuntu 10.10 to 11.04, and occurs on both 3.6 and 3.7. I don't use Unity.

Does any one know of a work around for this issue?
Comment 20 Julek Kopczewski CLA 2011-10-03 02:35:04 EDT
(In reply to comment #19)
> I should add for completeness that this started happening when I switched from
> Ubuntu 10.10 to 11.04, and occurs on both 3.6 and 3.7. I don't use Unity.
> 
> Does any one know of a work around for this issue?

I've observed the same thing. I don't remember seeing this before I switched to 11.04. I use Gnome3 so no Unity either.
Comment 21 Bogdan Gheorghe CLA 2011-10-03 11:45:50 EDT
There seems to be 2 problems here:

1) shell.setVisible is slow on GTK

We believe the test case is not realistic as does not spin the event loop. The event queue is being flooded with undispatched events. If you were to move the readAndDispatch into the loop, the performance goes from 2 minutes to less than 10 seconds:

        for (int i = 0; i < 1000; i++) {
            shell.setVisible(false);
            //shell.setText("shell" + i); //$NON-NLS-1$
            shell.setVisible(true);
            while (display.readAndDispatch()) {
            }
        }

A normal application will always spin the loop, so we believe issue 1 is not a real problem. However, it might be the case that the JDT junits are not running the event loop. (Deepak, is this true?) On setVisible, we are currently dispatching a set of events until GDK_MAP is received. If we add (GDK_VISIBILITY_NOTIFY, GDK_PROPERTY_NOTIFY, GDK_WINDOW_STATE) to the set, the queue will no longer be flooded and the performance is reasonable. We will release a fix for this.

2) shell.setVisible hangs

We were not able to reproduce this but we could see how you could get stuck in the loop if a mapped event is not received. Unfortunately without a reproducible case, we can't do much more. We'll leave Bug 349287 to track this issue. If anyone has any steps for us, please post it there.

Thanks!
Comment 22 Bogdan Gheorghe CLA 2011-10-03 12:13:47 EDT
Fixed in master > 20111003

Please give it a try and let us know if there are any problems.
Comment 23 Bogdan Gheorghe CLA 2011-10-03 12:14:06 EDT
Closing as fixed.
Comment 25 Deepak Azad CLA 2011-10-10 02:34:01 EDT
(In reply to comment #21)
> real problem. However, it might be the case that the JDT junits are not running
> the event loop. (Deepak, is this true?) 
Yes, that is correct. Note that we have had issues on linux in the past by running the event loop inside the for loop, for example e.g. see bug 330353 comment 9. On other platforms this does not seem to matter.

I verified with I20111005-0925 that the snippet from comment 0 now runs fast, and our performance test from bug 343242 also works better on my linux machine (this still needs to be verified on the build machines)

Thanks for the fix!
Comment 26 Steffen Pingel CLA 2011-10-17 11:30:51 EDT
The bug does not have a target milestone set. In which release will this fix be available?
Comment 27 Terry Parker CLA 2012-02-03 18:05:24 EST
(In reply to comment #26)
> The bug does not have a target milestone set. In which release will this fix be
> available?

Ping.  Is this patch applied to the 3.7.2 release, or only to 3.8?
Comment 28 Remy Suen CLA 2012-02-03 21:23:25 EST
(In reply to comment #27)
> Ping.  Is this patch applied to the 3.7.2 release, or only to 3.8?

A target milestone is set on this bug. The fix was released to the 3.8 stream and is not in 3.7.x.
Comment 29 Aaron Digulla CLA 2012-02-04 06:13:37 EST
Eclipse hangs/crashes for me at least once a week since 3.7 because of this bug and two others. Can you please seriously consider to backport it to 3.7.2?