Material-ui: import cost is too much

Created on 4 Dec 2017  路  13Comments  路  Source: mui-org/material-ui

I am using extension 'import-cost' in VSCode and it shows me import cost below:

import Button from 'material-ui/Button'; is 36.3K gzipped
VS
import Button2 from 'muicss/lib/react/button'; is 4K gzipped

I just simply compare these 2 UI framework and result is just a button!
Why size of material-ui is 9x of muicss?

"material-ui": "^1.0.0-beta.22",
"muicss": "^0.9.30",

performance

Most helpful comment

20 kB gzip comes from JSS,

A one-time cost though, right? Unless you only use one Button and no other components.

Partly it's also a tradeoff for having a combined flat, raised and FAB in one component.

All 13 comments

@saostad What about the CSS payload size?

how can i measure it ?

+6 kB with https://cdn.muicss.com/mui-0.9.30/css/mui.min.css.
Yeap, so we definitely have a higher initial entry price 馃 .
20 kB gzip comes from JSS, cc @kof. I have tried to reduce the footprint as much as possible.
But I think that we need to do better.
Hopefully, it doesn't hurt the performance that much:

20 kB gzip comes from JSS,

A one-time cost though, right? Unless you only use one Button and no other components.

Partly it's also a tradeoff for having a combined flat, raised and FAB in one component.

For comparison, Bootstrap CSS is 23 kB gzipped

I can reduce the size of the core a a bit by moving internal plugins to separate repos (function values and observables).But this will save probably 1kb at the end. The core itself is about 6kb right now. https://bundlephobia.com/[email protected]

The biggest issue with the reduction of plugins is compatibility. I think that we can do it, but we need to remove public api for generic styling. User should use whatever he/she wants, for e.g. directly react-jss. Internal styling should stay internal, that gives you power to optimize without running into issues.

Just noticed that material-ui depends on lodash. Wouldn't be better to depends on lodash-es to take benefits of tree-shaking?

@stunaz We're using:

import debounce from 'lodash/debounce';

So there's nothing to shake.

That's an interesting plugin. Here are some other pretty high numbers that I've found:

image

If anyone want to dig into the issue, he can run:

yarn build && yarn size:overhead:why

capture d ecran 2017-12-06 a 00 12 48

I have found an interesting leverage to improve the story here:

  • Removing flow Props from the /src
  • Migrating the class components to functions. Transpiling a single class introduce 1.8 kB non gzipped.
  • Using explicit propTypes over generated one. The current propTypes generation situation is pretty bad (I don't know when the regression was introduced, but it was working with beta.16). They are no linked (no runtime checks 馃槺 ) nor removed from the production code (dead code 馃惓, I think it never worked with flow).

I'm closing the issue as we have made some progress since it was opened (-7% #9453).
We will keep an important focus on this subject as I think it can be a real blocker for the library adoptions. Many people start using the lib as they need one or two components, a switch for instance. The lower the overhead is for them, the better. The Button component is quite a complex one. I hope that the upcoming Button implementation revamps for matching the specification will allow us to make it smaller :). Thanks everybody for the feedback! If you see a new potential for improvement, let us know.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reflog picture reflog  路  3Comments

mattmiddlesworth picture mattmiddlesworth  路  3Comments

ghost picture ghost  路  3Comments

anthony-dandrea picture anthony-dandrea  路  3Comments

sys13 picture sys13  路  3Comments