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

[docs] Improve bundle size option 2 advantage wording #17577

Merged
merged 8 commits into from
Sep 28, 2019

Conversation

ilanbm
Copy link
Contributor

@ilanbm ilanbm commented Sep 25, 2019

Speed is identical between option 1 and 2.


#### fast-imports

Converts all @material-ui/core top level imports to direct path imports

-import Card, { CardActions, CardContent } from '@material-ui/core';
+import CardContent from '@material-ui/core/CardContent';
+import CardActions from '@material-ui/core/CardActions';
+import Card from '@material-ui/core/Card';
find src -name '*.js' -print | xargs jscodeshift -t node_modules/@material-ui/codemod/lib/v4.0.1/fast-imports.js

on https://material-ui.com/guides/minimizing-bundle-size/ it says that direct path imports are the fastest way. Current existing codemodes don't satisfy the need to rapidly use this fast import option.
screenshot from minimizing-bundle-size doc:
image

@mui-pr-bot
Copy link

mui-pr-bot commented Sep 25, 2019

No bundle size changes comparing d28f415...90d2c90

Generated by 🚫 dangerJS against 90d2c90

@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 25, 2019

on https://material-ui.com/guides/minimizing-bundle-size/ it says that direct path imports are the fastest way.

@ilanbm The Babel plugin on https://material-ui.com/guides/minimizing-bundle-size/#option-2 is meant to provide equal bundling speed. If somebody cares enough to apply a codemod, would it be better to use the Babel plugin instead?

@eps1lon
Copy link
Member

eps1lon commented Sep 26, 2019

TL;DR Optimizations should be handled at compile time not manually.

It makes more sense to put this into a babel plugin since this can give us the freedom to move things around internally and address that in the babel plugin. Any optimization with a codemod has to be reapplied if the codemod improves/changes. Same applies to new code that you introduce which also needs this codemod applied.

We had this stance on the /es build as well. Put path transforms into a single place instead of spreading it throughout the entire codebase.

@eps1lon eps1lon closed this Sep 26, 2019
@ilanbm
Copy link
Contributor Author

ilanbm commented Sep 26, 2019

@eps1lon the goal here is to have fast imports that don't need extra compilation / tree shaking.
So what you suggest contradicts the goal of having a simple way to change imports to the fast way, doing it on compilation contradicts the goal

@ilanbm
Copy link
Contributor Author

ilanbm commented Sep 26, 2019

@oliviertassinari if option 2 has equal bundling speed, then why is it the direct import titled "fast"?

@eps1lon
Copy link
Member

eps1lon commented Sep 26, 2019

So what you suggest contradicts the goal of having a simple way to change imports to the fast way, doing it on compilation contradicts the goal

I'm pretty sure that by doing it during transpilation webpack won't pick up the first bundle. We're implementing naive tree-shaking at the transpiler level. The cost of rewriting an import is negligible.

But if you have some benchmarks comparing a babel plugin which rewrites the import with pre-rewritten imports then I would take a look again. Otherwise I'll reiterate that optimizations should almost never be done manually. That's what a compiler is for.

@oliviertassinari oliviertassinari added the docs Improvements or additions to the documentation label Sep 26, 2019
@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 26, 2019

@ilanbm I would propose that we focus on the documentation. If the page makes you think that option 1 is the fastest, then we don't do a good job with the current wording. It's fast, as much as option 2 with the Babel plugin. I think that we can expand this sentence.

This option provides the best DX and UX.

Should we continue the documentation changes in this pull request?

@ilanbm
Copy link
Contributor Author

ilanbm commented Sep 26, 2019

@oliviertassinari I agree, if they are fast the same way than the docs weren't so clear
(and thanks for the chrome autofill commit :) )

@oliviertassinari oliviertassinari changed the title [codemode] new missing codemode: fast-imports [docs] Improve bundle size option 2 advantage wording Sep 26, 2019
@oliviertassinari
Copy link
Member

oliviertassinari commented Sep 26, 2019

@ilanbm I have tried to improve the wording with a new commit. Let us know if it's better of it you have a different suggestion :).

@ilanbm
Copy link
Contributor Author

ilanbm commented Sep 26, 2019

@oliviertassinari it's way better now, now it is clear. thanks!

Copy link
Member

@joshwooding joshwooding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great re-wording!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants