Slower executables with dune

I’m new to dune and experiencing some 20% slowdown with the executables built with dune compared the ones produced with my good old Makefile where I specify options -no_assert -unsafe -inline 100. I tried to do the same with flags in my dune configuration:

(env
  (dev
      (flags (:standard -w -50-32-27-9-69-34-37-33))
      (ocamlopt_flags (:standard -unsafe -noassert -inline 100))))

However, I can see with dune build --verbose that many other options are passed to the compiler (like -g) by default, which might (or not?) lead to a slow-down. Is there any way to optimize dune for performance in this respect?

Have you tried building your executables in “release” mode (dune build --profile release) ? Otherwise Dune will build using -opaque which optimizes compilation time but disables cross-module inlining.

Cheers,
Nicolas

Thank you for your suggestion. Unfortunately, I didn’t notice any runtime difference with “–profile release” (nor did I with the addition of “-g” in the Makefile, which did not noticeably slow down my executables, so “-g” is probably not the culprit).

Hard to say more without more details. A small reproduction case or even having access to the Dune log of a full build (_build/log) could help.

Cheers,
Nicolas

The problem could be that you’re changing the flags for the dev environment, and not for the release environment.

Try this:

(env
  (release  ;; <- notice the change here
      (flags (:standard -w -50-32-27-9-69-34-37-33))
      (ocamlopt_flags (:standard -unsafe -noassert -inline 100))))

And then dune build --profile release.

1 Like