Js_of_ocaml output performs considerably worse when built with --profile=release flag

Adding
(js_of_ocaml (flags (:standard --no-inline)))
to the dune file in bin/web speeds up the release benchmark by quite a lot.

Super good find! Adding the --no-inline flag to the release build resulted in ~400FPS in my local environment, which is ~3.3 times more than release without --no-inline and ~1.5 times more than non-release (i.e. dev) build. I have summarized the result in the below chart:
jsoo_compare

The “release with --no-inline” also reduced the JS bundle size from 1MB to 52KB when compared to the dev build, which is nice.

So in summary, in this case, the cause of the bad performing release build was inlining (this may be related to some JIT optimization as @OCamlUser guessed, but I am not sure). My non-release dev build was performing better probably because it happened to be unable to do the inlining due to restrictions of separate compilation.

I kind of assumed that some optimization was missing from the release build and didn’t think of the possibility that the optimization itself was the cause.

@OCamlUser Thanks a lot! Will mark your comment as the solution.

7 Likes