Skip to content
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

Dead code elimination issue? #24

Closed
metametadata opened this issue Dec 26, 2016 · 2 comments
Closed

Dead code elimination issue? #24

metametadata opened this issue Dec 26, 2016 · 2 comments

Comments

@metametadata
Copy link

metametadata commented Dec 26, 2016

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.

- To save 700KB, fix cljsjs/material-ui
- To save more, stop using material-ui, or
- Wait for Closure and ClojureScript to support npm/commonjs module processing which would allow running dead code elimination on material-ui code
  1. This material-ui issue by @nha.
@metametadata
Copy link
Author

metametadata commented Dec 27, 2016

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
Copy link
Owner

madvas commented Dec 27, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants