OCaml 5.0 and OpenGL

Hello,

I did some tests with OCaml 5 and OpenGL (more precisely Gles3 available from opam). Here is the problematic:

I want a 2 threads architecture with one thread doing OpenGL and one thread doing some computation.
Communication between the two threads is currently via a queue protected by a mutex and condition (which could be improved). The OpenGL thread is waken up by keyboard/mouse events and is refreshing the display 60 times per second.

The problem in OCaml 4 was that the interface was never reactive enough unless you add so many Thread.yield that the computation is significantly slowed down. The problem is that the inner loop may not allocate or very little and context switching is not performed often enough.

As expected OCaml 5 solves the problem and the cost is around 10%: the batch mode for my program takes 108s, while the interface mode takes 121s for the same computation, keeping some key pressed to have the GL thread doing the maximum of work.

This is a very good news for me! Thanks for the work!

Now we just have to wait OCaml 6 to launch domains on GPU ?

Cheers,
Christophe

5 Likes