10

In Java 7 and 8 there is a bug in Swing menus that causes it to be slow when running an application remotely over X11 while other X11 applications are running. This issue was introduced in Java 7 and has never been fixed. Does anyone have any suggestions on a workaround. Using nxclient addresses this Swing menu issue, but introduces its own unwelcome issues.

The steps to reproduce the Swing menu issue are: - run any X11 application locally with some activity - log into a remote server using ssh -Y someserver - execute any Java GUI application (e.g. jvisualvm) running Java 7 or 8 - select a menu and observe a several second delay in response

Tom Pelaia
  • 1,275
  • 10
  • 9
  • 1
    Do you have a link to the specific bug? I don't seem to have this issue. – splungebob Sep 23 '14 at 19:58
  • No, I don't have a link to the bug, but it is easy to reproduce with any Java 7 Swing based application that has a menubar (e.g. jvsisualvm) or even a Combo Box. I posted a bug with Bug Id: 9007234 to http://bugs.sun.com but it doesn't show up in the bug database. – Tom Pelaia Sep 24 '14 at 12:33
  • Apparently, it's not easy to reproduce. As I said, I don't seem to have this issue in my Java 7 Swing app that has a JMenuBar and dozens of JComboBoxes. – splungebob Sep 24 '14 at 19:21
  • Steps to reproduce: 1) open an xterm 2) launch about five or more xclock applications (running locally) or another local X11 application that updates its UI more frequently 3) ssh -Y YourID@remoteserver 4) /usr/local/java/jdk1.7.0_13/bin/jvisualvm 5) start selecting menus from the jvisualvm and note the delay which does not occur with java 6 The more the local X11 app updates its UI the more significant the delay in the remote Java app's menu response, but Java 6 has no noticeable lag. – Tom Pelaia Sep 24 '14 at 20:02
  • Run about 20 xclock applications locally using xclock -update 1 and make sure they are all fully visible (not obscured). In our real world scenario which we've been running for over ten years we have multiple X11 applications running locally on linux consoles and we ssh to a remote server to run our java applications. There is no problem running them in Java 6.x but every version of Java 7 has the issue of delayed menu response (about 10 seconds) in our real environment. – Tom Pelaia Sep 24 '14 at 20:32
  • Cannot reproduce any noticeable delay. Maybe 500ms at most. – splungebob Sep 25 '14 at 13:55
  • Okay, I have a better demonstration. 1) open xterm 2) launch firefox and point it to the URL: http://web.ornl.gov/~t6p/Main/WebPlot/demo/live/livedemo.xhtml 3) ssh -Y YourID@remoteserver 4) run java 7 version of jvisualvm using & to run in the background 5) run java 6 version of jvisualvm using & to run in the background Note that the menus in java 6 respond very quickly but those in java 7 are really sluggish. – Tom Pelaia Oct 01 '14 at 20:34
  • Reproduce - try exporting java swing X app from linux server overseas ... spin up server in Paris say using https://www.scaleway.com/ then install java and attempt to manage your Android SDK versions on that remote host by launching command: android using ssh -X ... just hangs forever – Scott Stensland Dec 26 '16 at 18:49

4 Answers4

8

Just spent an entire day trying to solve the same issue. There's barely any info out there.

Local machines:

  1. Linux FedoraCore 20, KDE desktop, NVIDIA GeForce 7300 LE
  2. Linux FedoraCore 20, KDE desktop, NVIDIA GeForce GT 720

Running remote Java GUI over ssh, swing popups are extremely slow for PC2. Desktop freezes until popup appears. On the other hand, PC1 runs very fast/smooth, with no problems at all.

Turns out, in my case, the problem is that PC2 has 2 monitors. The closest bug report I could find is: JDK-8004103 : sun.awt.X11.XToolkit.getScreenInsets() may be very slow and it appears to be still open.

Temporary Workarounds:

  1. In KDE, Disable second monitor, Launch Application, Enable second monitor
  2. Work in Gnome Desktop (My Gnome environment not affected by this issue)
  3. Launch remote Java app using Java 6 (Issue not present in Java6)

None of these are ideal workarounds, but considering that my Desktop freezes for 3-4 seconds every time I click on a menu item, they'll do for the time being.

AndreasP
  • 81
  • 3
  • What version of gnome do you not experience the issue? I have tried using gnome that comes with RHEL 6.1 and still experience the issue. – bdrx Nov 13 '14 at 21:54
  • Fedora20 has Gnome 3.10. – AndreasP Nov 14 '14 at 22:19
  • I've tried Fedora running Gnome 3.10.4 and it still has the slow menu bug. – Tom Pelaia Dec 17 '14 at 13:35
  • I have the same issue on ubuntu : $ cat /etc/issue Ubuntu 14.04.3 LTS \n \l $ uname -a Linux 3.13.0-68-generic #111-Ubuntu SMP Fri Nov 6 18:17:06 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux The combo boxes are slow too. I have no problem when disabling the secondary monitor. Java = java version "1.8.0_66" – Stéphane Millien Dec 10 '15 at 08:55
  • Switching to Gnome fixed it for me (was using LXDE) – wakjah Oct 24 '16 at 14:24
3

I finally found much better workaround for this problem. When opening the SSH connection to the remote computer, set ForwardX11Trusted option to "no".

ssh -o ForwardX11Trusted=no -X user@host.domain

For me, opening a ComboBox reduced from ~14s to instantly. Unfortunately, I currently don't have any Java applications with Swing Menu installed on the server, but I think this should work for Menus too.

If you don't want to type that option every time, add the following line to ssh config file (/etc/ssh/ssh_config)

ForwardX11Trusted no
MlinarG
  • 41
  • 3
1

Well, there still doesn't seem to be much information out there on how to work around this problem and running an application via remote X11/xinerama makes it practically unusable. In particular, menu navigation takes an eternity. The work-around that we employed has 2 parts to it.

  1. At the startup of your application call: JPopupMenu.setDefaultLightWeightPopuEnable(false);

    This will force the popups to use heavy weight popups. Lightweight popups make multiple calls to the X windows across the network to determine what is visible, obscurred, etc. When operating over remote X11 this becomes a very expensive call. Lightweight popups make these calls everytime the popup becomes visible. Heavyweight popups make this call when they are 1st invoked, but every successive popup action reuses the heavyweight component that I'm guessing is managed by the window manager so the menus thereafter are very responsive.

  2. Create a new XineramaJMenu class that extends JMenu. This class must override the method:

    protected Point getPopupMenuOrigin() {...}

copy the code for this method from JMenu, but replace the line:

 Insets screenInsets = toolkit.getScreenInsets(gc);

with

 Insets screenInsets = new Insets(0,0,0,0);

This eliminates the getScreenInsets(...) call, which makes multiple calls to the remote X server to determine the max inset values of the child windows. We eliminate this expensive call across the network and accept a default 0 inset.

Unfortunately, this will require you to replace all instances of JMenu with XineramaJMenu, but it at least results in usable menus when running your application over remote X11.

EddieW
  • 11
  • 1
0

I was able to solve this problem on a RHEL 7 system with NVidia graphics board and NVidia driver 340.96 running KDE 4.14.8 by adding this option to the Screen section of the X server config file.

Option         "nvidiaXineramaInfo" "Off"

The NVidia driver manual has this to say about this option:

The NVIDIA X driver normally provides a Xinerama extension that X clients (such as window managers) can use to discover the current layout of display devices within an X screen. Some window mangers get confused by this information, so this option is provided to disable this behavior.

Perhaps KDE is one of the window managers that gets confused?