two simple tips to speed up ocaml compilation

The dose3 code base is getting larger and larger and waiting 40 secs each time I want to recompile the library is not acceptable anymore. Recently I tried to understand why the ocaml compiler was so slow .

To compile dose, I use a combination of ocamlbuild, ocamlfind, camlp4 and Makefile to drive everything.

The first important problem was related to my naive use of camlp4. I extensively use the Camlp4MacroParser module for the conditional compilation of certain features and actually I use camlp4 to process all my source code. The bottom line her is that using the byte code version of camlp4o is definitely a bad idea.

To use the native binary you need to change the pre-processing directive in the file _tags :

<*/*.ml{i,}>: pp(camlp4o.opt -I_build Camlp4MacroParser.cmxs)

This will use the opt version of camlp4 and the cmxs instead of the .cma. The next problem is that debian, for some reason (I guess lack of time, more then anything else), does not ship the cmxs libraries of the Camlp4MacroParser. In other to make this available, I added a simple compilation rule in my make file to create the file Camlp4MacroParser.cmxs in the _build directory.

 ocamlopt -shared $(shell ocamlc -where)/camlp4/Camlp4Parsers/Camlp4MacroParser.cmx -o _build/Camlp4MacroParser.cmxs

The second BIG problem I solved yesterday was related to the tag traverse. Since I use git as VCS, every invocation to ocamlbuild was triggering a recursive traverse of all the .git directory with a considerable waste of time.

To solve this problem, I've reverted the default ocamlbuild and explicitly add only those directory that I'm really interested to traverse.

true: -traverse
<{common,algo,doseparse,deb,rpm,applications,experimental}/**>: traverse

This is actually needed not to compile the code itself, but to generate the documentation with ocamldoc.

Average: 4 (3 votes)

Comments

The "-traverse" tag is a new

The "-traverse" tag is a new one and me, and makes a nice difference on some local projects. Thanks for the tip!

You explain how 40s is too

You explain how 40s is too long for you, and the optimizations you found... but fail to disclose how much time was gained!

All considered, I think I now

All considered, I think I now can compile in about 20 seconds ... But this is not an exact measure ...

Noted as wishlist bug against

Noted as wishlist bug against the debian camlp4 package: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=690114

Thanks Ralf !!!

Thanks Ralf !!!

> for some reason (I guess

> for some reason (I guess lack of time, more then anything else), does not ship the cmxs libraries of the Camlp4MacroParser

Or, possibly, because noone has noticed this before :-)

Did you report it as a bug? Please, do!

It is not that noone noticed

It is not that noone noticed (we did actually), but since noone requested it…