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

Inline tests are included in binaries built with js_of_ocaml #74

Open
copy opened this issue Feb 18, 2018 · 2 comments
Open

Inline tests are included in binaries built with js_of_ocaml #74

copy opened this issue Feb 18, 2018 · 2 comments
Labels
forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.

Comments

@copy
Copy link

copy commented Feb 18, 2018

For example:

(executable
  ((name test)
   (js_of_ocaml ((flags (:standard --opt 3 --pretty +weak.js))))
   (libraries (js_of_ocaml core_kernel))))

With test.ml containing:

let _ = Core_kernel.Time.now ()

And building with jbuilder build test.bc.js.

The generated test.bc.js contains quite a few calls similar to the ones below:

                    test_unit
                     (_u4_,
                      _aCq_,
                      0,
                      _aCp_,
                      793,
                      4,
                      63,
                      function(param){return test(1,3609444,_aCo_)});
                    test_unit
                     (_u4_,
                      _auK_,
                      0,
                      _auJ_,
                      333,
                      4,
                      214,
                      function(param)
                       {return round_trip$0
                                (to_parts$1(create$31(0,0,[0,hr],0,0,0,0,0,0)))});
     _avr_=caml_new_string(": <<test true 71 1666750235549516973L>>"),
     _avt_=caml_new_string("src/time_ns.ml"),
     _avu_=caml_new_string(": <<test true 4398 1232807081547132235L>>"),
     _avw_=caml_new_string("src/time_ns.ml"),
     _avx_=caml_new_string(": <<test false 702561 1233263206897519979L>>"),
     _avz_=caml_new_string("src/time_ns.ml"),

Note that this is at the maximum optimisation level that jsoo supports (as far as I know). jsoo is able to remove the entire module if it isn't referenced (for example when test.ml is empty), but it doesn't seem to be able to remove the values exported for the inline tests.

@hhugo
Copy link

hhugo commented Feb 18, 2018

You can force js_of_ocaml to drop test by passing the following flags:
(js_of_ocaml ((flags (:standard --setenv FORCE_DROP_INLINE_TEST=true)))).

see comment in ppx_inline_test

@copy
Copy link
Author

copy commented Feb 19, 2018

Thanks, this reduced my bundle size significantly (from 736K to 529K).

I'd suggest this to be documented somewhere, but from my view this issue can be closed.

@hhugo hhugo self-assigned this Mar 26, 2018
@github-iron github-iron added the forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system. label Nov 25, 2020
@hhugo hhugo removed their assignment Mar 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.
Projects
None yet
Development

No branches or pull requests

3 participants