so regarding tree-shaking, if we put aside the mentioned pr for a moment, and take a look at this bit of text (from here):
As a matter of style, it is also recommended to group small libraries together into "bundles" that are updated, tested, and deployed together. Since Janet libraries are often quite small, the cost of downloading more functionality that one might need isn't particularly high, and JPM can remove unused functions and bindings from generated standalone binaries and images, so there is no runtime cost either.
when i first read this i thought what was being referred to by:
JPM can remove unused functions and bindings from generated standalone binaries and images
was user-defined things and not built-in janet things.
i'm still not sure what it is referring to (possibly both user-defined and built-in bits).
in any case, i did a little experiment to try to observe size differences with attention being given to user-defined things only.
sample code [1] i used had the file (sample/sample/init.janet):
(import janet-peg/rewrite)
(import janet-peg/grammar)
(import janet-peg/location)
(defn hello
`Evaluates to "Hello!"`
[]
"Hello!")
(defn main
[& args]
(pp location/loc-grammar)
(print (hello)))when i build an executable, as a side-effect, a sample.c file ends up in my build directory.
the sizes of some relevant files were:
sample.c- 16,194 bytesbuild___sample.o- 8,408 bytessample- 2,135,672 bytes
if i comment out (pp location/loc-grammar) and rebuild:
sample.c- 3,120 bytesbuild___sample.o- 5,272 bytessample- 2,131,576 bytes
so there definitely is a reduction in size here -- much more apparent in sample.c and somewhat apparent in build___sample.o and sample.
in any case, just sharing some exploration results.
[1] for reference, i generated the project using:
jpm new-exe-project sample
and i edited project.janet to add dep info so that it ended up as:
(declare-project
:name "sample"
:description ``` ```
:version "0.0.0"
:dependencies ["https://github.com/sogaiu/janet-peg"])
(declare-executable
:name "sample"
:entry "sample/init.janet")
i then did jpm --local deps to prepare for subsequent invocations of jpm --local build, etc.