Time spent synchronizing with OpenGL thread

I’m trying to optimize the speed of my application (Scilab) which is for now a bit too slow.
I’m using a GLJPanel with the Java2d OpenGL pipeline enable and manually call its display function.

I ran some benchmarks and find two major issues that slow down rendering.
The first one is text displaying (altghough I’m using only a single TextRenderer to draw all my text).
The second is the time spent waiting for the OpennGL thread in the display function.

I added a timer in the GLJPanel display function and one in paintImmediatelyAction.


public void display() {
    if (EventQueue.isDispatchThread()) {
      // Want display() to be synchronous, so call paintImmediately()
      paintImmediately(0, 0, getWidth(), getHeight());
    } else {
      // Multithreaded redrawing of Swing components is not allowed,
      // so do everything on the event dispatch thread
      try {
	long initSec = System.nanoTime();
        EventQueue.invokeAndWait(paintImmediatelyAction);
	long endSec = System.nanoTime() - initSec;
	System.err.println("Time before display = " + (endSec * 1.0e-6));
      } catch (Exception e) {
        throw new GLException(e);
      }
    }
  }

Basically



class PaintImmediatelyAction implements Runnable {
    public void run() {
      long initSec = System.nanoTime();
      paintImmediately(0, 0, getWidth(), getHeight());
      long endSec = System.nanoTime() - initSec;
      System.err.println("time spent in paint immediately =" + (endSec * 1.0e-6));
    }
  }

Basically the time spent in paint immediately is 1 millisecond which is perfectly usable time for my application.
However the total time of the display function is around 10 milliseconds.
It is not too long but not all the user have a computer as recent as I have.

This is the time for my application which is using some GUIs (menus, an input console) in addition with the GLJPanel.
I ran the same test on simple JOGL demos using only a JFrame to enclose the GLJPanel and there the synchronization time is almost negligible.

So apparently it is not a JOGL issue. However I was wondering if anyone already had a similar problem. Or maybe if there was a way to know what was currently running on the Eventqueue.

Thank you,
Jean-Baptiste

Try removing the JOGL code from your app and running a profiler against it to see where the time on the Event Dispatch Thread appears to be going.