Experiments in JITting

Hello to everyone; I have implemented an experimental JIT compiler for the OCaml interpreter. It is very rough, just a way to prove myself that what I have in mind is feasible, rather than something that can be actually used in practice, but it seems to work. What I would like to do now is to benchmark it on some nontrivial OCaml program to determine the speed gain, if any, that it might provide. The problem is that I have no idea of which OCaml applications exist that I could benchmark, and that could benefit from JIT compilation. Can anyone suggest me something?
Thank you in advance
Pietro

Even though filters are perhaps not the best use case for JITs, an idea would be to make an opam switch that doesn’t install the native code compilers (Not sure if there’s a configure option for that you may have to tweak the install target). Compile a selection of package. Make another switch that has only the bytecode version of the compilers and your jit, install the same selection and see how it fares.

The obvious application that benefits from JIT compilation is the ocaml toplevel (REPL). (You could for example compare with ocamlnat).

configure has --disable-native-compiler or, for a released version, opam switch create 5.2.0+bytecode ocaml.5.2.0 ocaml-option-bytecode-only will similarly remove the native compilers. For the JIT version, it should work with opam switch create jit --empty followed by opam pin add ocaml-variants git+https://…your-fork…#jit-branch-name

Ah but the idea was still to have a native code switch, except with the bytecode executables of the compilers.

I misunderstood what you meant by native compilers - although there should be a significant number of packages (thanks to 5.x’s lack of 32bit native) which build as bytecode - so testing both the compiler as bytecode only and packages themselves?

Yeah well my wording was not exactly stellar :–) Of course testing the byte-code only switch is an option. I just thought there were maybe more interesting code paths to jit in native code compilation (optimisations etc.).

In fact on a 4.12.2 switch it seems the toolchain still installs with both .opt and .byte versions of the programs with suffixless programs symlinked to .opt (I thought this had been changed at some point to simply install the “best” available executables). So it may just be a matter of resymlinking to the .byte executable after the install.

Actually, I think this should be possible without any tweaking using the “classic” build instructions - configure normally followed by make -j world and make -j opt and then make install should quietly ignore the lack of the .opt compilers

1 Like

To get a rough idea of the speedup, you can simply run the tests found in testsuite/tests/misc in the compiler distribution (bdd.ml, nucleic.ml, boyer.ml, etc). If memory serves, these tests have parameters to make them do more work and take longer which could also be useful.

Cheers,
Nicolas