0.5.3
Dead code elimination
Originally I didn't anticipate including cljs-devtools into advanced builds because currently custom formatters do not work under advanced optimizations. Until now, my approach in projects including cljs-devtools was to require cljs-devtools only into development builds and completely skip it in advanced builds using modified :source-paths
set.
Recently @domkm raised a valid expectation that cljs-devtools should play well with advanced builds:
Advanced compilation is not eliding dead code as I would expect it to. With
goog.DEBUG
asfalse
,(when ^boolean goog/DEBUG (devtools/install!))
causes cljs-devtools to be included in the advanced build even though that is the only use of cljs-devtools in the project. Any ideas why it's not being elided?
When you:
- properly configure
goog.DEBUG
to be "statically" false via :closure-defines - put
(devtools/install!)
behindgoog.DEBUG
conditional (or any other conditional which is statically false) - there is no other mention of devtools functionality in your code
- THEN it should completely elide the library from your advanced builds.
It could look something like this. Please note that ^boolean hint is important for closure advanced optimizer to clearly understand that the conditional will always evaluate to false
:
(if ^boolean goog/DEBUG (devtools/install!))
Alternative method could be to write a simple macro which would emit (devtools/install!)
call only if under advanced build (for example there is an environmental property set signalling that).
I'm happy to announce that the above techniques work as expected since v0.5.3. Also I have added tests to ensure this won't break in the future and advanced builds will do full elide in those cases.