Why does OPAM recompile so much?



It seems like recently, OPAM constantly recompiles libraries I already have installed when I install a new one. This isn’t just me – it’s happening to everyone I know working with OCaml. I don’t remember this happening in the past.

Anybody know why this is happening? It makes installing a list of packages take very long, since OPAM constantly needs to go back and rebuild packages it built before.


Is it possible

  1. Some library L that you have installed is used by many others,
  2. L has many depopts?


This isn’t the opam bug report forum. I believe bug trackers are more appropriate for this. But, please give:

  1. result of opam config report
    2… OS/Distrib
  2. Potentially offending package/query.


The cases of recompiling usually happens when one or more dependencies of a package is upgraded/downgraded/recompiled. OPAM explicitly tells you the reason why a package is recompiled, e.g.:

donwgrade   bar     1.0.1 to 1.0.0  [required by foo]
recompile   baz     1.2.3           [uses bar]
install     foo     2.0.1

and you can use it to trace the changes.

Please ignore this if you already understand, but just in case: In this case, the newly installed foo depends on bar@1.0.0 while previously baz@1.2.3 uses bar@1.0.1, so OPAM resolves the version that fits all requirements, therefore downgrading bar to 1.0.0. Because there is a change in bar, the packages that depend on bar, namely baz, needs to be recompiled.

I think that it makes sense and is expected. Do you encounter strange cases other than this?


Thanks @bobbypriambodo. It’s been more of a general sense of this happening for me, and has been highlighted by my friend just installing several opam switches from scratch, trying to find an OCaml version that worked for the packages he needed. As such, since the most recent experience is my friend’s, I don’t have a detailed log, but I’ll try to pay attention in future.

The final comment my friend made on this matter was that installing packages one by one would cause many repeat recompilations, but listing all the packages on one opam line did only one set of recompilations. Perhaps this is a sign of depopts then, as @antron stated.


Ah, I remember also doing this as a newbie (still am). IIRC I was trying to install Core (I think it was prior to v0.9.0) and got confused that the installation didn’t work for 4.04.0… I ended up having to try 4.02.3 and 4.03.0.

Yes, if you provide all the packages to install beforehand, OPAM should be able to do better resolving and resolves the versions that satisfy all the requirements, hence only one recompilation. Great catch, hopefully it could lessen your friend’s confusion :slight_smile: