Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bundle size: Load CMIs dynamically #6

Open
bryphe opened this issue Apr 15, 2019 · 2 comments
Open

Bundle size: Load CMIs dynamically #6

bryphe opened this issue Apr 15, 2019 · 2 comments

Comments

@bryphe
Copy link
Member

bryphe commented Apr 15, 2019

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:

  • Use the jsoo_mkcmis tool to create a JS CMI
  • Hook into toplevel module load code to dowload these dynamically, instead of referring to the bundled CMI
@bryphe
Copy link
Member Author

bryphe commented Apr 15, 2019

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
Copy link
Member Author

bryphe commented Apr 15, 2019

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant