Most of the issues listed have been fixed in the more recent version of Scilab
On Scilab-5.0 alpha version you may have notice that Scilab is much slower than Scilab 4.
After investigation we found several major bottlenecks:
Bottlenecks
Text rendering
- Text rendering in OpenGL is quite tricky. It needs to create bitmap textures for each text to draw and then put the texture on a quad.
JOGL API provides a class TextRenderer which highly simplify the processes. Basically it is used by specifying the font, the text and the place to draw. The texture mechanism is hidden. However displaying text seems to be very slow and creates some memory leaks. Some users has already complained that the class is slow, and the JOGL's developer argued that some applications were displaying lot of text without slowdowns. However, he did not provide any pointer or any way to improve the speed.
Synchronization with OpenGL thread
- All OpenGL instructions must be performed on a single thread (we call it OpenGL thread). It appears that for the GLJPanel, the OpenGL thread is the
Eventqueue aka EventDispatcher. One commentary in the GLJPanel says "Multithreaded redrawing of Swing components is not allowed, so do everything on the event dispatch thread". Actually when calling the display function of the GLJPanel (basically what is performed when a graphic object is modified or an explicit call to the Scilab draw routine) the code try to synchronize with the OpenGL thread before launching any OpenGL action. Here is the code of the function: {{{public void display() {
if (EventQueue.isDispatchThread()) {
- // Want display() to be synchronous, so call paintImmediately() paintImmediately(0, 0, getWidth(), getHeight());
- // Multithreaded redrawing of Swing components is not allowed, // so do everything on the event dispatch thread try {
EventQueue.invokeAndWait(paintImmediatelyAction);
- throw new GLException(e);
- }
It uses InvokeAndWait for synchronization. Each time, it needs around 10ms before the paintImmediatelyAction is called on a recent computer (core 2 duo, 4Gb RAM). That's a lot compared to the paintImmediatelyAction. for example with a plot3d (without ticks, just box and surface) it takes between 1 and 2ms to render. It still unclear what Swing/AWT may do suring this time. However, when using JOGL demos, with only a JFrame enclosing the GLJPanel, the synchronization time become negligible (less than 1ms).
Use of Java2D OpenGL Pipeline
- In standard mode, GLJPanel uses images to fill the GLJPanel. After each rendering cycle, the JOGL read the newly filled OpenGL buffer then copy it into an image and send the image to display. This is time consuming, specially with large window or fullscreen. However, since Java 1.6, JOGL is able to use render the OpenGL buffer almost directly using Java2D. The speed increase is important but the graphic card need to support pbuffers. Today, only the Nvidia cards are implementing them correctly. With ATI the support is buggy and on Intel cards it is probably not supported.
Benchmarks
Synchronization with OpenGL thread
scf(); drawlater(); plot3d; a = gca(); a.axes_visible = "off"; drawnow(); for i = 1:10000,a.rotation_angles(2) = i;end;
Java2d / OpengGL pipeline Enable
window
Temps moyen nécessaire pour la fonction display : 5.5ms
Temps moyen nécessaire pour OpenGL : 2.5ms
full screen
Temps moyen nécessaire pour la fonction display : 7.5ms
Temps moyen nécessaire pour OpenGL : 4.5ms
Java2d / OpengGL pipeline Disable
window
Temps moyen nécessaire pour la fonction display : 9ms
Temps moyen nécessaire pour OpenGL : 6.5ms
full screen
Temps moyen nécessaire pour la fonction display : 35ms
Temps moyen nécessaire pour OpenGL : 26ms
scf(); drawlater(); plot3d; a = gca(); a.axes_visible = "off"; drawnow(); realtimeinit(1); for i = 1:1000,realtime(i);a.rotation_angles(2) = i;end;
Java2d / OpengGL pipeline Enable
window
Temps moyen nécessaire pour la fonction display : 3.0ms
Temps moyen nécessaire pour OpenGL : 1.75ms
full screen
Temps moyen nécessaire pour la fonction display : 5.5ms
Temps moyen nécessaire pour OpenGL : 4ms
Java2d / OpengGL pipeline Disable
window
Temps moyen nécessaire pour la fonction display : 5ms
Temps moyen nécessaire pour OpenGL : 3.5ms
full screen
Temps moyen nécessaire pour la fonction display : 21.5ms
Temps moyen nécessaire pour OpenGL : 20.5ms
Text Rendering
scf(); drawlater(); plot3d; xstring(0,0,"Scilab power!!!"); a = gca(); a.axes_visible = "off"; drawnow(); for i = 1:5000,a.rotation_angles(2) = i;end;
Java2d / OpengGL pipeline Enable
window
Temps moyen nécessaire pour la fonction display : 6ms
Temps moyen nécessaire pour OpenGL : 3ms
full screen
Temps moyen nécessaire pour la fonction display : 7ms
Temps moyen nécessaire pour OpenGL : 4.5ms
Java2d / OpengGL pipeline Disable
window
Temps moyen nécessaire pour la fonction display : 10ms
Temps moyen nécessaire pour OpenGL : 8ms
full screen
Temps moyen nécessaire pour la fonction display : 36ms
Temps moyen nécessaire pour OpenGL : 27ms