-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
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
[core] Optimize clsx usage #15589
[core] Optimize clsx usage #15589
Conversation
@material-ui/core: parsed: -0.78% 😍, gzip: -0.84% 😍 Details of bundle changes.Comparing: 9634f29...b5111e4
|
@merceyz Sweet :) |
@merceyz What's left to be ready for review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would caution against compiler optimizations with our current testing setup. We don't run the tests with our production code nor do we track our build output.
I would feel more comfortable if the clsx author could sign-off on the plugin. One reason for the clsx switch was perf which was supported by benchmark. Is this still the case for the transformation? As far as I know variadic function calls are more expensive.
@material-ui/core: parsed: -0.78% 😍, gzip: -0.85% 😍 Details of bundle changes.Comparing: bb5b5b4...9473e25
|
cc @lukeed |
I haven't seen or used this plugin yet but it looks promising 👍 Variadic arguments are expensive to traverse if you're accessing This plugin flattens arguments, which reduces the need for recursive calls. That's a big performance gain. In the benchmarks this moves callers from "Nested ___" to "Strings" performance. All benchmarks are already handling variadic arguments. |
@lukeed Thanks :) |
It's a good point. I think that we should apply this babel plugin to the tests. |
I added a couple of benchmarks, the performance gain was greater than I thought, main goal was to reduce size.
@lukeed Added some benchmarks to show that gain, thanks for taking the time to look into this.
@oliviertassinari Just more optimizations, but that can come later.
|
@merceyz It looks like you have a few broken cases to handle 😆. |
@oliviertassinari Interesting thing is I already test that one https://github.com/merceyz/babel-plugin-optimize-clsx/blob/d658abc8d9c6bd5f80215641e72e1233f2e766a3/test/objects.test.js#L108 |
@oliviertassinari Build is green |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy to give it a try. Who's in?
Hold on, can we run the visual regression tests with this plugin too? |
If we always want the plugin to run, shouldn't we just add it in here? https://github.com/mui-org/material-ui/blob/1458ab53c93585c8ad1e3de8425f3e28e8ed5e64/babel.config.js#L54-L59 |
I have no objection with it 👍. |
@oliviertassinari How did you benchmark #15023? Would be nice if |
@merceyz I have used https://deploy-preview-15589--material-ui.netlify.com/performance/table-mui. But don't expect any change. I have seen https://github.com/merceyz/babel-plugin-optimize-clsx/tree/master/benchmark. |
That, and the size savings :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff. Reduced bundle size with perf boost and we don't have to change how we write code. Doesn't get much better than that.
Added the babel plugin
babel-plugin-optimize-clsx
(https://github.com/merceyz/babel-plugin-optimize-clsx) that optimizes and minimizesclsx
function calls