-
Notifications
You must be signed in to change notification settings - Fork 51
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
Is dead code elimination really working? #37
Comments
Interesting observations. But I'm sorry I'm not going to investigate it. Currently each release of cljs-devtools performs following dead-code elimination sanity check:
It seems to work in this case. But I don't check files sizes or how it affects non-devtools code. One possible theory could be that although devtools namespaces are not present, still requiring them triggers Google Closure to compile-in more of the standard library. For example whole cljs printing machinery ( Please investigate it further and let me know. You might also want to test more recent ClojureScript versions because this might be dependent on Google Closure compiler version. |
Nice catch! Unfortunately, updating Clojurescript to
Here are the updated sizes:
This is way over my league, but I'll gladly follow your lead if you have more ideas. Regarding your DCE sanity check:
|
I was curious. I have just added some helper scripts to compare DCE in scenarios you described. You can run My output looks like this:
These results are consistent with my theory:
During writing these scripts I got completely puzzled by behaviour of lein/cljsbuild/cljs-compiler. It looks like cljs compiler incorrectly reuses caches between individual cljsbuild builds. That caused that my results were illogical and depended on the order of compilation of individual cljsbuild builds and cljs compiler cache state. I had to brute-force |
Oh, there was a typo on the scripts that I managed to overlook three times in a row... I've corrected the second row above. The results went back to the previous distribution, just a bit larger. Yup, I had already been bitten by this cljsbuild behavior, it's almost a "standard". I've just tried the whole procedure with Thanks for the attention (and for cljs-devtools!) The results for
|
I dug deeper into this and I have some bad news. So far I identified following problems:
Please note that I don't have a good solution for this right now. I was able to work-around [1]
|
Ok, I was able to shave off quite some dead weight: The small difference between NO_DEBUG and NO_REQUIRE is caused by requiring |
Wow, that's really great! It effectively brought DCE back as a viable option. Following today's Clojurescript release (with the accompanying Google Closure version bump), here are the new results:
Your version of "I'm sorry I'm not going to investigate it" is putting our's "I'm 110% on it" to shame. Thank you! |
Wait, I was too fast. It didn't work as expected. |
The solution with devtools.optional namespace didn't work in scenario when cljs-devtools was required as a library via maven dependency. In that case we cannot (goog/require "devtools.optional") because the \ file is not compiled/present. There does not seem to be a way how to conditionally require something based on compiler options. So I decided just emit a compile-time warning to warn users and leave it as is. People should not use cljs-devtools in :advanced mode. And ideally they should include it via :preloads which has no effect in :advanced mode.
Unfortunately when the library is packaged as maven dependency the optional requires didn't work. At least I implemented a compile-time warning. The solution is to use |
Oh, sad to hear. Perhaps it'd be useful to other library/tool writers if you post something on Clojurescript's mailing list. At the very least you'll have more experienced eyes on the matter. I've collected some threads below related to DCE, but I'm not really qualified to assess whether you've stumbled on something new/different or not, so I'll leave them here for your appraisal:
|
I can't seem to bring the code size down with a barely empty project through dead-code elimination alone, even when following the installation instructions to the letter.
The template used was reagent-figwheel with only
devtools
andreagent
as dependencies. I've fiddled with thegoog.DEBUG
flag, and then removeddevtools
from the:require
and:dependencies
vectors.:dependencies
+:require
+goog.DEBUG true
:dependencies
+:require
+goog.DEBUG false
:dependencies
+:require
+ no mention at all:dependencies
+ no:require
+ no mention at all:dependencies
+ no:require
+ no mention at allThe first two rows followed the instructions from the release notes. There's a single mention of
(devtools/install!)
within a(when ^boolean js/goog.DEBUG ...)
block. The other three had this line removed manually.Google Closure's shaved 400kb of the build, but that's still a 800kb increase for a
:require
without a single mention ofdevtools
! Is this the best I can expect from dead code elimination?Here's the code used for the builds (e.g.
lein new reagent-figwheel +devtools
):The text was updated successfully, but these errors were encountered: