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

Bundle size is way too big #7304

Closed
kof opened this issue Jun 30, 2017 · 27 comments
Closed

Bundle size is way too big #7304

kof opened this issue Jun 30, 2017 · 27 comments

Comments

@kof
Copy link
Contributor

kof commented Jun 30, 2017

Despite the fact that I am importing specific components only and those are maybe 5. I see in my bundle analyzer this huge dependency. Lets find out why that is so and what can we do about it. Also 60kb of lodash inside sounds like an overkill.

screen shot 2017-06-30 at 4 40 32 pm

@kof kof changed the title Bundlesize way too big Bundle size way too big Jun 30, 2017
@kof kof changed the title Bundle size way too big Bundle size is way too big Jun 30, 2017
@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 30, 2017

Are the stats coming from the production build? The documentation of the propTypes is pretty large in dev mode.

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

Dev, lets see whats in production.

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

Now minified (parsed size) version looks much better, but still way too much for those components I use.

screen shot 2017-06-30 at 6 28 07 pm

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

Potentially something is still importing the entire lib. I checked my code, I am def. only importing specific files.

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 30, 2017

I can't see the Dialog, nor the Avatar being imported.

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

Hmm, I am not using Paper for e.g. but probably its a hardcoded dependency of some other components like a Menu or something. I am using List, ListItem, Button, Divider, LinearProgress, Chip, IconButton, Input, Menu, Form, MuiThemeProvider.

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

Its quite a number of components, but still, 115kb minified ... React-DOM is 110kb for e.g. React 15kb.

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

For e.g. that lodash dependency 60kb, is it really worth it?

@oliviertassinari
Copy link
Member

oliviertassinari commented Jun 30, 2017

I have something pretty close to you:
capture d ecran 2017-06-30 a 18 54 33

First finding lodash.isEqual shawnmcknight/react-scrollbar-size#2. I think that we can greatly reduce the size of the Tabs component by not depending on it.

For e.g. that lodash dependency 60kb, is it really worth it?

We use very few functions of lodash, I'm surprised that we depend on 60 kB of it!

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

We use very few functions of lodash, I don't think that material is depending on 60kb of loadash.

Then its either the core or not specific imports.

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

Btw. why is lodash not in your stats? Probably because the same version is used in the project globally. I am still on lodash 3 globally, thats why it shows me the cost of lodash within material-ui scope.

@oliviertassinari
Copy link
Member

To put some perspective on my common.js bundle:

capture d ecran 2017-06-30 a 19 03 01

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

And here is mine ... now you know why I am digging, thats insane.
screen shot 2017-06-30 at 7 07 14 pm

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

Just started optimizing though.

@oliviertassinari
Copy link
Member

Wow, I can't even see Material-UI in your bundle. You can start with supertest and all the moment locales :happy:. Also, I have only share the common.js of my app. I have also many more chunk for each page.

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

You can))) second column at the bottom. Yes, moment locales and other monsters are on my kill list.

@oliviertassinari
Copy link
Member

I'm gonna address the lodash.isEqual shawnmcknight/react-scrollbar-size#2 issue, but I don't know what you could do aside that to improve the bundle size.

@kof
Copy link
Contributor Author

kof commented Jun 30, 2017

Yeah, I think for material-ui is worth considering removing lodash if its trivial things and review all imports to make sure nothing unneeded is imported.

@oliviertassinari
Copy link
Member

Oh, we might have another lodash function messing the bundle size. I'm gonna look into that.

@oliviertassinari
Copy link
Member

Oh and a last one, we should split the colors file.

@oliviertassinari
Copy link
Member

Here we are #7306. That should help, a lot.

@mehrdad-shokri
Copy link

mehrdad-shokri commented Apr 1, 2018

@kof @oliviertassinari I'm facing this exact problem. I'm importing components like import Button from 'material-ui/Button' way. any hints?

@maciej-gurban
Copy link
Contributor

maciej-gurban commented May 5, 2018

I believe there could still be some issues with components importing too much. I've got a bunch of components in my output bundle that don't seem to be in any way related to the components I've imported. For reference, here are all import statements from material-ui within my app and my vendor bundle:

import List, { ListItem } from 'material-ui/List';
import List, { ListItem, ListItemText, ListItemSecondaryAction } from 'material-ui/List';
import { TableBody, TableRow, TableCell } from 'material-ui/Table';
import { TableHead, TableRow, TableCell } from 'material-ui/Table';
import Typography from 'material-ui/Typography';
import Card from 'material-ui/Card';
import Table from 'material-ui/Table';
import Hidden from 'material-ui/Hidden';

screen shot 2018-05-05 at 14 56 36

If you have ideas how to investigate what actually imports Input, Modal, Form, Select etc, I'd love to get some pointers.

@oliviertassinari
Copy link
Member

oliviertassinari commented May 5, 2018

@maciej-gurban All the extra imports come from material-ui/Table. The issue will be addressed with #9673. We are going to flatten the imports.

@maciej-gurban
Copy link
Contributor

maciej-gurban commented May 5, 2018

@oliviertassinari Thanks for a quick reply and the explanation! For now I've changed all my imports to point directly to the files they import, so instead of

Foo, { FooBar } from 'material-ui/Foo'

I'm doing

Foo from 'material-ui/Foo/Foo'
FooBar from 'material-ui/Foo/FooBar'

This removed all the unnecessary modules from my bundle. Big props for creating those standalone modules.

@kennblvnp
Copy link

what app are u using guys? those squares that indicates the size

@mehrdad-shokri
Copy link

@kennblvnp it's webpack bundle analyzer

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

No branches or pull requests

5 participants