madvas / cljs-react-material-ui

Clojurescript library for using material-ui.com
Eclipse Public License 1.0
205 stars 32 forks source link

Dead code elimination issue? #24

Closed metametadata closed 7 years ago

metametadata commented 7 years ago

I have a sample project which uses Reagent. Merely including the cljs-react-material-ui dependency adds about 500kb to the compiled .js file (using advanced compilation mode; before gzipping). It's not really expected because no code from the library is actually used yet in the project's codebase (well, except the React which is "included" into cljs-react-material-ui?).

This is how I add the dependency:

before:

[reagent "0.6.0" :exclusions [cljsjs/react]]
[cljsjs/react-with-addons "15.3.1-0"]          

after:

[reagent "0.6.0" :exclusions [cljsjs/react cljsjs/react-dom]]
[cljs-react-material-ui "0.2.34"]

If the Closure compiler can't eliminate the dead code in this primitive case than I can also conclude that it will not be able to optimise the code when I require and really use a few Material UI components from the library. Is this correct? Can this be somehow fixed to make compiler eliminate code for MaterialUI components not used in my codebase?

After some experiments it looks like dead code elimination only kicks in if there are no mentions of React in my codebase.

Related stuff

Can these issues be somehow related to the described problem?

  1. The mailing group post:
    
    Cljsjs/material-ui required by cljs-react-material-ui increases output size by about 1.4MB.
    700KB of that is necessary, other 700KB is caused by bug in cljsjs/material-ui which causes the code be included twice.
  1. This material-ui issue by @nha.
metametadata commented 7 years ago

I'm going to close this. If I understand everything correctly, the root problem is that material-ui is not written in the Google Closure "way".

cljs-react-material-ui depends on cljsjs/material-ui which in turn includes material-ui via :foreign-libs mechanism. And foreign libs are not a subject to DCE.

madvas commented 7 years ago

yes, dead code elimination doesn't work for any cljsjs library, one you require it in a namespace you buy a whole package