Modelio icon indicating copy to clipboard operation
Modelio copied to clipboard

Serious performance issue with GTK3, no problem with GTK2

Open cluxter opened this issue 4 years ago • 6 comments

Hi

My environment:

OS: ArchLinux
Modelio version: 4.1.0
Desktop environment: XFCE and Gnome
CPU: AMD Ryzen 9 3950X (16 cores/32 threads)
RAM: 64 Gb DDR4 @3200 GHz
GPU: Nvidia GeForce GTX 670
GPU driver: nvidia (proprietary)
Motherboard: ASUS ROG Crosshair IV Formula

I experience very very poor performance when running Modelio with GTK3 (which is the default setting). When I use GTK2 instead like this:

SWT_GTK3=0 /opt/modelio/modelio

performance goes back to normal. It's night and day. Actually, GTK3 performance is so bad that it comes to a point where Modelio is just unusable. I experience this on 3 different machines (all of them using ArchLinux).

I attached (Example1.zip) a State Diagram which is composed of 16 states and ~30 transitions. It takes about 3 seconds on my high end PC (description above) to update the diagram when I move around one state, for example the sub-state State 3. It takes up to 8 seconds on my laptop with the same diagram, just for one move! Every time I move something around, 1 core of the CPU reaches 100% for several seconds until it refreshes the display, and meanwhile the whole application gets stuck. So even if Modelio can be run, it just can't be used using GTK3, I've got to force using GTK2 if I want to be able to use it in Linux.

Some other projects also experience a similar problem:

  • Inkscape: https://bugs.launchpad.net/inkscape/+bug/1723247
  • gvim: https://github.com/vim/vim/issues/1199

GTK3 should obviously be used over GTK2 since it supports HiDPI scaling and is supposed to be future proof with the support of Wayland, so I think we should really address this issue.

I tried changing the display backend using GDK_BACKEND=wayland in Gnome but Modelio wouldn't run, it wants x11. I tried switching to different GTK3 themes like Arc, Breeze, Adwaita:dark, it didn't change anything. I tried turning off font anti-aliasing by putting these options in modelio.ini:

-Dawt.useSystemAAFontSettings=off
-Dswing.aatext=false

but it didn't change anything (except that it was more ugly). I tried using the default Modelio diagramming theme instead of my custom "Black and white" theme, it didn't change anything.

From other projects experiencing similar issues, it looks like it comes from the way GTK3 is handled in the Modelio source code. Or maybe it's just that GTK3 is really poorly designed, I don't know.

@modelio-cde @aabherve @frederic-ferran-softeam @phv78 : could you please at least confirm or deny this behavior?

I will be glad to help in the debugging process and provide as many data as needed to fix this issue.

Thank you very much and thanks a lot for Modelio, it really is a great tool :)

cluxter avatar Dec 04 '20 12:12 cluxter

Hi Cluxter,

We know that Modelio may have some issues when running with GTK3, and that's why we recommended running Modelio with GKT2 instead. In the modelio.sh script, the SWT_GTK3 environment variable is set to "0" to address this issue. So in order to run Modelio properly, please run the modelio.sh.

Your diagnostics about GTK3 is correct, Modelio has some issues in GTK3 such as the processor running at 100%. In fact, the problems come from the Webkitgtk library which is used by Modelio and doesn't works correctly with GTK3.

These issues might be fixed when we switch to Java 11 to build and run Modelio (Modelio is currently built and run with Java 8).

Thank you for your feedback and your support.

frederic-ferran-softeam avatar Jan 18 '21 17:01 frederic-ferran-softeam

Hi @frederic-ferran-softeam and thank you for your answer.

As you're probably aware, GTK 4 was released 1 month ago. The official announcement specified that GTK 2 is now considered as obsolete. Quoting the blog post:

GTK 4 is now stable, and we consider it ready for consumption. That does not mean GTK 3 is dead – we will continue to support and update it for the foreseeable future (the latest release, 3.24.24, quietly went out a few days ago). It does mean, however, that GTK 2 has reached the end of its life. We will do one final 2.x release in the coming days, and we encourage everybody to port their GTK 2 applications to GTK 3 or 4.

Are you considering migrating Modelio to GTK 4 in a not-too-distant future? It may be relevant to consider this migration even before doing the migration from Java 8 to Java 11, but I don't know what's your vision on this and what has priority.

Again, thanks for your answer.

cluxter avatar Jan 20 '21 12:01 cluxter

Some technical analysis and references for the record:

  • The SWT library seems to suppport GTK 4, more or less : https://bugs.eclipse.org/bugs/show_bug.cgi?id=540385
  • We should use the latest SWT version
  • we are stuck on an Eclipse RCP 4.9, latest RCP is 4.18, next one is 4.19
  • we are stuck on GTK 2 because GTK 3 Webkit widget interactions with Jetty internal help server trigger a crazy bug in the JDK : https://bugs.openjdk.java.net/browse/JDK-8238279
  • The JDK bug seems to not occur on Java 11
  • Eclipse RCP needs java 11 since version 4.17, sources:
    • https://www.eclipse.org/eclipse/development/readme_eclipse_4.17.php#mozTocId315234
    • https://www.eclipse.org/lists/platform-dev/msg02345.html
    • https://bugs.eclipse.org/bugs/show_bug.cgi?id=564035

cedric780 avatar Jan 22 '21 13:01 cedric780

Thank you so much @cedric780 for all these details, it looks like you spotted the exact origin of the bug.

So updating to Java 11 would solve the high CPU usage when using GTK 3.

In the bug report that you posted (https://bugs.openjdk.java.net/browse/JDK-8238279), you said that you wrote a patch to fix it. Since it will probably take some time before Modelio is migrated to Java 11, would it be possible to apply this patch one way or another on the Modelio source code (more precisely on the JDK that it embeds, if I understand the bug report correctly) temporarily until Modelio is migrated to Java 11?

Having a version of Modelio which works with GTK 3 would be more valuable than a version which doesn't, even if I understand some people would argue that it's a hack and things should be done the right way. The problem is that it might take a while before we can see Modelio using Java 11 and your patch could be applied quickly, effectively solving the bug from a functional point of view, before the migration occurs later on.

cluxter avatar Jan 22 '21 13:01 cluxter

@cedric780 I explored the source code of your patch and I was able to compile it this way:

$ mvn package

Then I used the instructions from the usage.txt file to modify the modelio.ini files from this:

-startup
plugins/org.eclipse.equinox.launcher_1.5.100.v20180827-1352.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.800.v20180827-1352
-clearPersistedState
-vmargs
-Xms512m
-Dpython.console.encoding=UTF-8
-Dorg.eclipse.swt.internal.webkitgtk.ignoretlserrors=true

to this:

-startup
plugins/org.eclipse.equinox.launcher_1.5.100.v20180827-1352.jar
--launcher.library
plugins/org.eclipse.equinox.launcher.gtk.linux.x86_64_1.1.800.v20180827-1352
--launcher.appendVmargs
-clearPersistedState
-vmargs
-Xms512m
-javaagent:/home/cluxter/EPollArrayWrapper-bug/jre-patch/target/org.modelio.jre.epollarray.patch-0.0.1.jar
-Dorg.eclipse.equinox.http.jetty.log.stderr.threshold=info
-Dpython.console.encoding=UTF-8
-Dorg.eclipse.swt.internal.webkitgtk.ignoretlserrors=true

Then I ran Modelio like this:

$ SWT_GTK3=1 /opt/modelio.sh

The first lines of the logs displayed on the Java VM were:

Added transformer.
Replaced sun/nio/ch/EPollArrayWrapper
Removed transformer.

So it looks like the patch was successfully applied. However, I didn't see any performance improvement in the UI.

Am I missing something?

cluxter avatar Jan 27 '21 18:01 cluxter

Hello, I successfully applied what I published here (based on the NOrbert response in the same thread):

https://askubuntu.com/a/1390138/1088668

dcremonini avatar Jan 30 '22 17:01 dcremonini