Why ppx_deriving_yojson bloats binaries?

Hello,

I have found that using ppx_deriving_yojson increases the size of the output executable by the order of 20 megabytes.

Why is this happening and is there anything I can do about it?

New empty project

$ dune init project hello_world
$ dune build
$ ll _build/default/bin/main.exe
... 1,5M ... _build/default/bin/main.exe*

Add ppx_deriving_yojson

$ tail bin/dune -n 2
(libraries ppx_deriving_yojson ppx_deriving_yojson.runtime)
(preprocess (pps ppx_deriving_yojson)))

$ dune build 
$ ll _build/default/bin/main.exe
... 21M ... _build/default/bin/main.exe*

21 MB!

1 Like

It looks like you added the deriver itself as a library dependency? Can you remove that and try again? See the readme for the correct dependency: GitHub - ocaml-ppx/ppx_deriving_yojson: A Yojson codec generator for OCaml.

1 Like

Oh yes, thank you very much! For some reason I always mistakenly listed ppx_deriving_yojson in the dependencies. :grimacing:

2 Likes