# Slower executables with dune

**URL:** <https://discuss.ocaml.org/t/slower-executables-with-dune/10343>\
**Category:** Ecosystem\
**Tags:** dune\
**Created:** [August 19, 2022, 9:48am UTC](https://discuss.ocaml.org/t/slower-executables-with-dune/10343 "2022-08-19T09:48:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andaman](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@Andaman](https://discuss.ocaml.org/u/Andaman)\
**Post date:** [August 19, 2022, 9:48am UTC](https://discuss.ocaml.org/t/slower-executables-with-dune/10343/1 "2022-08-19T09:48:49Z")

</div>

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:

```auto
(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?

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [August 19, 2022, 10:01am UTC](https://discuss.ocaml.org/t/slower-executables-with-dune/10343/2 "2022-08-19T10:01:58Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Andaman](https://avatars.discourse-cdn.com/v4/letter/a/b3f665/32.png) [@Andaman](https://discuss.ocaml.org/u/Andaman)\
**Post date:** [August 19, 2022, 11:34am UTC](https://discuss.ocaml.org/t/slower-executables-with-dune/10343/3 "2022-08-19T11:34:59Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [August 19, 2022, 1:46pm UTC](https://discuss.ocaml.org/t/slower-executables-with-dune/10343/4 "2022-08-19T13:46:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![keleshev](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/keleshev/32/3779_2.png) [@keleshev](https://discuss.ocaml.org/u/keleshev)\
**Post date:** [August 22, 2022, 11:00am UTC](https://discuss.ocaml.org/t/slower-executables-with-dune/10343/5 "2022-08-22T11:00:58Z")

</div>

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

Try this:

```auto
(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`.
