Hacker News new | ask | show | jobs
by giraj 1204 days ago
I was hoping this post would mention using OCaml with flambda[1] enabled. At least for my work, flambda seems to yield a ~10% speed up when compiling things. Can you get OCaml binaries with flambda enabled through Nix? With opam, I currently have to compile OCaml myself to enable it, as I am not aware of any binaries being distributed.

[1] https://v2.ocaml.org/manual/flambda.html

3 comments

The nix option for it was added in 2017:

https://github.com/NixOS/nixpkgs/pull/32946

If you find it important, I'd encourage opening a PR to ask for flambda to be enabled by default at https://github.com/NixOS/nixpkgs/issues/new/choose.

Especially if the ocaml community typically enables flambda by default these days.

Seems you would need to first override ocaml and then override the ocaml used in mkOcamlPackages. [1]

  let o = ocaml.override { flambdaSupport = true; }; in
  let oP = ocaml-ng.mkOcamlPackages o (self: super: {}); in
  oP.apron
[1] https://discourse.nixos.org/t/install-ocaml-flambda-compiler...
Okay, thanks! But doesn't this still mean you have to compile ocaml (with flambda) yourself?
If the derivation has already been written (as GP implies), then compiling something yourself with Nix is essentially just a longer installation process. No downloading tarballs, no keeping track of things in /usr/local, no stow or manually adding things to your path. Nix is essentially a source distribution that pulls common binaries from caches.
I actively work on an OCaml project and couldn’t understand anything about what flambda does from its readme
I updated the link to point to the docs, which are more informative. As far as I understand, flambda is an intermediate representation of OCaml which allows for a number of optimisations and better inlining. You can check if you already have flambda enabled by runnning "ocamlopt -config | grep flambda".

If you're using opam then you can test flambda out by creating a new switch

  opam switch create ocaml-flambda ocaml-variants.4.14.1+options ocaml-option-flambda
and then running "opam switch set ocaml-flambda". (You can replace 4.14.1 with your preferred version above.)
It's a bunch of optimisation passes, I believe mostly around inlining. Ocaml is historically quite passive on that.