I have been running 1.15 locally for a while and 1.14 in production. I just upgraded production to 1.15.7 and noticed that the “code” size is different between dev/prod. I’m not sure what the expected behaviour is nor do I know what “code” memory means. I’m naively assuming it’s the size of the beam file AST in memory? Is this supposed to be static based on the deploy size or something else entirely? Erlang manual says:
Releases default to preloading all modules, mix defaults to loading modules on demand to increase startup performance in favor of slightly slower first time response when a new module is used. That‘s likely the difference you see between prod and dev.
If you want to lower memory footprint you likely want to cut out what you don’t need – not disable preloading. What you actually need will eventually be loaded, so your footprint wouldn’t actually get smaller.
There is no automatic prunning of modules or functions. The feature added in 1.15 is around code paths, which brings mix projects closer to how releases are built by excluding everything but explicit dependencies mostly to otp applications. Previously all of OTP would be available for loading on demand.
To get a smaller codebase you’d need to lessen the (number of) applications you depend on, as there’s also nothing manual for pruning code at the module or function level.
Code path pruning
I had skipped a rather important word when reading about code path pruning.
Code memory usage
Turns out running mix release.init creates rel/env.sh.eex which has the RELEASE_MODE option right at the top . I migrated from distillery, so it wasn’t obvious what I was looking for. Anyone starting off with a fresh project would easily find this option.
rel/env.sh.eex
# # Set the release to load code on demand (interactive) instead of preloading (embedded).
# export RELEASE_MODE=interactive
Also, this may not affect startup time in OTP 26.
Final results
Using interactive mode after going thru all the routes has reduced the memory:
Production is running at 23MB right now, but I expect it will grow to at least 30MB. Embedded mode which preloads everything had code memory usage at 48MB. Super-helpful when running on lower memory nodes. A MB saved is a MB earned.