Is rescript/bsc significantly faster than jsoo?

This comparison is of compile time, not of generated code.

I don’t have hard data for this. However, from goofing around, rescript/bsc seems quite a bit faster than jsoo. Anyone else experiencing this? If so, any intuition on why rescript/bsc is able to achieve these compile time speed ups?

When targeting js with js_of_ocaml, you have the extra step through byte code.
Use cases and features are different between jsoo and rescript. For instance, jsoo ppx might be responsible for additional typing time. The jsoo minifier, enabled by default (with program compilation) could affect timing. Same thing with source map support.

I would suggest collecting data if you want a better answers.

Maybe @jeffsco could provide some data as he moved some project from rescript to jsoo.

I might be unreasonable here, but Jsoo webgl example : seconds to compile - #8 by hhugo does not feel fast to me.

We are adding a “\n” to a ~400 line file, doing an incremental build. My measurements are 1.6s, your measurements are 0.97s. Either way, this feels slow compared to the likes of esbuild / bsc. In fact, this feels slower than Rust → wasm incremental builds, and makes me hesitant to build largeish (50k loc projects) on this tech.

I understand that jsoo currently goes through various ocaml stages; but I’m really wondering about the costs in compile time.

I’m not exactly sure why recompiling that webgldemo.cmo takes so much time.

Just to test I tried this test_gl which uses Brr’s interface to webgl and doing exactly what you suggest (adding a \n in the shader). With separate compilation I get the recompilations below, that is 39.3ms for the regenerating the cmo. The example is a bit simpler but not dramatically simpler.

Wild speculation ahead: are we perhaps looking at slowness due the typing of objects ?

[1]

> b0 log -u     
[004:spawn 12ms test_gl e:72ec746ee4c75997] ['…/bin/ocamldep' '-slash' '-modules' '/private/tmp/gl/test_gl.ml' > '/private/tmp/gl/_b0/b/user/test_gl/ocaml-srcs.deps'][0]
[010:spawn 39.3ms test_gl e:e7531f76a732a1bb] ['…/bin/ocamlc' '-c' '-bin-annot' '-g' '-o' '/private/tmp/gl/_b0/b/user/test_gl/test_gl.cmo' '-I' '/private/tmp/gl/' '-I' '…/lib/brr/' '/private/tmp/gl/test_gl.ml'][0]
[018:spawn 291ms test_gl e:76b05a5964c26d12] ['…/bin/js_of_ocaml' 'compile' '-o' '/private/tmp/gl/_b0/b/user/test_gl/test_gl.cmo.js' '--source-map' '/private/tmp/gl/_b0/b/user/test_gl/test_gl.cmo'][0]
[019:spawn 17.3ms test_gl e:c6fbd8914239dee8] ['…/bin/js_of_ocaml' 'link' '-o' '/private/tmp/gl/_b0/b/user/test_gl/test_gl.js' '--source-map' '/private/tmp/gl/_b0/b/user/test_gl/ocamlrt.js' '/private/tmp/gl/_b0/b/user/test_gl/stdlib.cma.js' '/private/tmp/gl/_b0/b/user/test_gl/jsoo_runtime.cma.js' '/private/tmp/gl/_b0/b/user/test_gl/brr.cma.js' '/private/tmp/gl/_b0/b/user/test_gl/test_gl.cmo.js' '/private/tmp/gl/_b0/b/user/test_gl/std_exit.cmo.js'][0]

The webgl demo is using the jsoo ppx that has a significant impact on typing I think. sourcemap is responsible for ~75% of the link time.
Again, you need to compare comparable things … and collect numbers.

1 Like

passing --no-runtime to js_of_ocaml compile would reduce timing a lot … at the cost of less efficient code. (We currently parse the entire js runtime everytime we compile something, just to extract few informations to run optimisation, on my TODO to improve)

1 Like

Thanks for the tip @hhugo !

First without source-map we shave 15ms of the above 291ms but then if we add --no-runtime it reduces by an order of magnitude. So a \n addition in the test file reduces to:

[004:spawn 12.1ms test_gl e:54298ccfe24fa4a6] ['…/bin/ocamldep' '-slash' '-modules' '/private/tmp/gl/test_gl.ml' > '/private/tmp/gl/_b0/b/user/test_gl/ocaml-srcs.deps'][0]
[010:spawn 37.3ms test_gl e:3e2bfc4bd4a21735] ['…/bin/ocamlc' '-c' '-bin-annot' '-g' '-o' '/private/tmp/gl/_b0/b/user/test_gl/test_gl.cmo' '-I' '/private/tmp/gl/' '-I' '…/lib/brr/' '/private/tmp/gl/test_gl.ml'][0]
[018:spawn 20.6ms test_gl e:c922aef3e144c246] ['…/bin/js_of_ocaml' 'compile' '-o' '/private/tmp/gl/_b0/b/user/test_gl/test_gl.cmo.js' '--no-runtime' '/private/tmp/gl/_b0/b/user/test_gl/test_gl.cmo'][0]
[019:spawn 17.4ms test_gl e:f34f1ce4ac8b702d] ['…/bin/js_of_ocaml' 'link' '-o' '/private/tmp/gl/_b0/b/user/test_gl/test_gl.js' '/private/tmp/gl/_b0/b/user/test_gl/ocamlrt.js' '/private/tmp/gl/_b0/b/user/test_gl/stdlib.cma.js' '/private/tmp/gl/_b0/b/user/test_gl/jsoo_runtime.cma.js' '/private/tmp/gl/_b0/b/user/test_gl/brr.cma.js' '/private/tmp/gl/_b0/b/user/test_gl/test_gl.cmo.js' '/private/tmp/gl/_b0/b/user/test_gl/std_exit.cmo.js'][0]
1 Like

Sorry but I don’t use dune. However I’m pretty sure that mutatis mutandis the brr dune instructions here should yield similar results.

It will partially be fixed in the next release

5 Likes