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

evaluate polished #15540

Closed
wants to merge 3 commits into from
Closed

Conversation

oliviertassinari
Copy link
Member

@oliviertassinari oliviertassinari commented Apr 30, 2019

I'm curious about the bundle size of https://polished.js.org/ as well as if we can easily migrate to it.

@oliviertassinari oliviertassinari force-pushed the evaluate-polished branch 4 times, most recently from cc2f67e to c180843 Compare April 30, 2019 21:51
@mui-pr-bot
Copy link

mui-pr-bot commented Apr 30, 2019

@material-ui/core: parsed: +3.73% , gzip: +3.76%
@material-ui/lab: parsed: +8.27% , gzip: +7.34%

Details of bundle changes.

Comparing: 02f135d...bf07138

bundle parsed diff gzip diff prev parsed current parsed prev gzip current gzip
@material-ui/core +3.73% 🔺 +3.76% 🔺 310,335 321,900 84,514 87,694
@material-ui/core/Paper +17.41% 🔺 +15.36% 🔺 67,623 79,394 20,115 23,205
@material-ui/core/Paper.esm +18.92% 🔺 +16.52% 🔺 60,988 72,526 19,034 22,178
@material-ui/core/Popper +0.02% 🔺 +0.29% 🔺 28,590 28,596 10,290 10,320
@material-ui/core/Textarea 0.00% -0.17% 5,513 5,513 2,379 2,375
@material-ui/core/TrapFocus +0.05% 🔺 -0.25% 3,780 3,782 1,577 1,573
@material-ui/core/styles/createMuiTheme +72.46% 🔺 +49.94% 🔺 15,943 27,495 5,777 8,662
@material-ui/core/useMediaQuery 0.00% -0.31% 2,106 2,106 976 973
@material-ui/lab +8.27% 🔺 +7.34% 🔺 139,630 151,178 42,533 45,656
@material-ui/styles +0.04% 🔺 +0.05% 🔺 51,151 51,173 15,148 15,156
@material-ui/system +0.05% 🔺 -0.46% 11,765 11,771 3,923 3,905
Button +13.53% 🔺 +12.18% 🔺 85,303 96,847 25,684 28,813
Modal +0.13% 🔺 +0.13% 🔺 20,365 20,392 6,695 6,704
colorManipulator +295.34% 🔺 +197.15% 🔺 3,904 15,434 1,543 4,585
docs.landing 0.00% +0.01% 🔺 51,531 51,531 11,368 11,369
docs.main +1.82% 🔺 +2.01% 🔺 648,758 660,570 202,565 206,633
packages/material-ui/build/umd/material-ui.production.min.js +4.02% 🔺 +3.74% 🔺 292,184 303,929 82,450 85,530

Generated by 🚫 dangerJS against bf07138

@oliviertassinari
Copy link
Member Author

oliviertassinari commented Apr 30, 2019

I have got my answers. The cost is +3 kB gzipped, I couldn't get tree-shaking working. The migration is relatively easy but we have a couple of visual fails: https://www.argos-ci.com/mui-org/material-ui/builds/47383 (I haven't looked at why).

@oliviertassinari

This comment has been minimized.

@eps1lon
Copy link
Member

eps1lon commented May 1, 2019

@mui-org/core-contributors I would vote for publishing our own helpers, an effort started in mui-org/material-ui/pull/14573/files#diff-c75e53d06f2b28b7a31c29692afe27b5.

Why not contribute to polished and make it tree shakeable?

@oliviertassinari
Copy link
Member Author

oliviertassinari commented May 1, 2019

@eps1lon Without tree-shaking, we get a bundle size report of +10kB gzipped. With ES5 module direct import, we get a bundle size report of +3kB gzipped. Will tree-shaking support help with the +3kB increase?

@oliviertassinari
Copy link
Member Author

oliviertassinari commented May 1, 2019

It's probably too early to publish @material-ui/css-utils. Let's provide responsive typography first. We can continue the CSS helper thread in a different effort. We don't need to batch them.

@oliviertassinari
Copy link
Member Author

oliviertassinari commented May 1, 2019

I believe the bundle size different comes from polished supporting features like https://github.com/styled-components/polished/blob/master/src/internalHelpers/_nameToHex.js.
It seems they are deliberately supporting more "edge cases" (I'm biased) at the expense of bundle size.

@eps1lon
Copy link
Member

eps1lon commented May 1, 2019

I'm not sure what you mean with no tree-shaking support. It seems to work just fine. The last state of this PR used path imports from the cjs bundle. CommonJS has very limited tree-shaking support. Why not go with the documented import style?

@oliviertassinari
Copy link
Member Author

oliviertassinari commented May 1, 2019

Why not go with the documented import style?

It was my first attempt, the whole library was included: bf07138.

CommonJS has very limited tree-shaking support.

Definitely.

@eps1lon
Copy link
Member

eps1lon commented May 1, 2019

And how did you come to the conclusion that tree shaking is not working? It looks like polished just has more features. I quickly tried it in a new create-react-app and it didn't pull in the full package.

@oliviertassinari
Copy link
Member Author

oliviertassinari commented May 1, 2019

how did you come to the conclusion that tree shaking is not working?

The bundle size increase reported was +10kB gzipped, exactly like BundlePhobia does. I assumed it wasn't working.

@oliviertassinari
Copy link
Member Author

Capture d’écran 2019-05-01 à 16 09 51

@@ -3,7 +3,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import clsx from 'clsx';
import { fade, withStyles } from '@material-ui/core/styles';
import { withStyles } from '@material-ui/core/styles';
import { fade } from '@material-ui/core/styles/colorManipulator';
Copy link
Member

Choose a reason for hiding this comment

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

@oliviertassinari This will pull in our commonJS build.

RemindMe: Write a lint rule that only allows 1st level path imports

Copy link
Member Author

Choose a reason for hiding this comment

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

It deoptimizes it. Thanks!
💯 for an eslint rule. You already mentioned this problem and fixed a couple of issues in the past. But I hadn't fully realized the implications.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah this adds a lot of confusion. It's not obvious what imports are fine and which are not.

For v5 we should revisit our packaging strategy so that people don't even have to choose how they import from our package.

Copy link
Member Author

Choose a reason for hiding this comment

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

For v5 we should revisit our packaging strategy so that people don't even have to choose how they import from our package.

What direction do you have in mind? I wish we were documenting:

import { TextField, makeStyles, Theme, PaperProps } from '@material-ui/core';

Copy link
Member

Choose a reason for hiding this comment

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

Or @material-ui/TextField. Either way I think an option for the import style is helpful. We can revisit this in a separate issue. Before a change I want to give users some time to give feedback in the form of the import style they use. This change should come with a codemod.

Copy link
Member Author

Choose a reason for hiding this comment

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

Or @material-ui/TextField.

A past effort: #9532, it was implemented with a codemod. I can't find the other thread about it, we discussed the usage of a package per component. The @material-ui/TextField strategy has important limitations: "dependency hell" being the biggest.
I think that it's also part of the reason why people want us to implement all the component here: so they don't have dozens of dependencies to handle. It's a net plus for DX. But it also has drawbacks, it's definitely a tradeoff. Damn, I wish I can find this thread.

Copy link
Member Author

Choose a reason for hiding this comment

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

I have found it. I thought it was more detailed, but it seems it just me arguing against myself: #7839 (comment). To give a proper debate.

@bhough
Copy link

bhough commented May 3, 2019

@oliviertassinari What is the goal with the potential move to polished?

I'm happy to help work on some sizing issues if it helps get polished integrated and saves you having to build and maintain your own helpers. Is it just the subset in this PR that you're looking at including?

@oliviertassinari
Copy link
Member Author

@bhough The motivation to use polished is to compound the community into a single CSS utility package. Material-UI's mission is to empower developers to build UIs with React. So far, we have a more or less (blurred boundary) private CSS utilities. To truly execute this mission, it's important for us to have an outstanding bundle size cost. People are afraid of bundle size bloat. This is also related to #13039.

@bhough
Copy link

bhough commented May 5, 2019

@oliviertassinari Makes complete sense.

We're working on both adding additional contrast functionality (getting ratio and adjusting it) as well as pulling preset values (like the CSS color names) into optional imports (which should address the majority of the size difference you're seeing).

In the spirit of this, we're happy to move 4.0 forward if there is a genuine interest in integrating polished into Material-UI.

@oliviertassinari
Copy link
Member Author

oliviertassinari commented May 5, 2019

genuine

@bhough We want to better align with the React community in Material-UI v5.

Depending on the trends in 6 months (we will focus on implementing new components in the next 6 months), It might mean moving to styled components, styled-system and polished. Now, there are a couple of challenges with each of these migrations. The challenge with polished is about bundle size, +3 kB gzipped is a blocker. We are going from 1.4 kB to 4.4 kB gzipped here, something is wrong. For us, It doesn't really matter where the CSS helpers are hosted, as long as the bundle size is awesome and they are well documented. We still don't document the color helpers after 3 years of existence. It has never been really important. The challenge with styled-system is the different theming structure it requires, creating a massive BCs most people can't handle. It's also about whether or not it worth it, the gain is limited.
The challenge with styled-components is to keep the first-class support for SASS and SC users that want to customize each class name variants. How do we generate global class names people can easily override?

@oliviertassinari oliviertassinari deleted the evaluate-polished branch February 8, 2020 20:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants