revery-ui / revery-playground

Live, interactive playground for Revery examples
https://www.outrunlabs.com/revery/playground
MIT License
17 stars 4 forks source link

Bundle size: Load CMIs dynamically #6

Open bryphe opened 5 years ago

bryphe commented 5 years ago

The bundle size for our toplevel is pretty huge - clocking in at 7MB. This means initial load of the playground is very slow. Much of this is due to the compiled CMI files (which describe the interface of modules - used by the toplevel typechecker).

We package a pretty huge amount of these - for the OCaml stdlib, for Revery, and for Revery's dependencies. Ideally, we could load them 'on-demand' so we don't need to download a giant bundle.

A way to do this would be:

bryphe commented 5 years ago

Example from @thangngoc89 on loading CMIs on demand:

https://sketch.sh/embed.html?value=cHJpbnRfZW5kbGluZSgiSGVsbG8gd29ybGQiKTsKbGV0IGEgPSAxKzE7CmEgPiAwOwpiOw==&package=https://sketch.sh/jsootop.cmis.js

(Add include JsooTop; and run - see jsooTop.cmis.js loaded)

bryphe commented 5 years ago

@thangngoc89 found the hook we can use for this: https://docs.mirage.io/ocaml/Env/Persistent_signature/index.html#val-load

and code snippet:

let backupLoad =  Env.Persistent_signature.load^;

let myLoad = (name) => {
    switch (backupLoad(name)) {
    | Some(a) => a
    | None => // Executing the external function to load the JS cmis script, and try again
    }
}
Env.Persistent_signature.load := myLoad