-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
InputControl: Use less Emotion styled API #58948
Conversation
2be26f7
to
03f52b0
Compare
Size Change: -341 B (0%) Total Size: 1.7 MB
ℹ️ View Unchanged
|
03f52b0
to
fb7130b
Compare
From my experimentation, it does seem like our use of Emotion is creating an unnecessary drag on component performance. It is harder to confirm with our "official" performance tests ( However, I am able to observe meaningful differences with the following test methods:
Observing with these two methods, it seems like minimizing our use of Emotion recovers most of the performance gap between TextControl and InputControl. Although InputControl also involves a lot of state reducer logic, This is kind of good, because we have no reason to be using a runtime library like Emotion anymore and we've already been talking about migrating to a build-time solution. Optimizing Emotion performanceAlthough I think we should just migrate away from Emotion rather than rewrite our Emotion code, I'll note here for completeness that there seems to be a usage pattern that is particularly bad for performance. A big improvement comes from removing dynamic prop-based // Bad
const StyledDiv = styled.div`
color: ${ props => props.color };
`;
<StyledDiv />
// Immediate improvement, even though it's still dynamic
const classes = cx( styles.dynamicColor( props.color ) );
<div className={ classes } /> Next stepsI will start investigating approaches to migrating away from Emotion. My first choice would be CSS Modules since their standard syntax feels like a safer bet in the long run. But I'd also like to experiment with Linaria because it's probably easier to integrate into our current build process, and would require much less code rewriting effort compared to CSS Modules. It could be a relatively quick win. |
I agree with this. In a few places we noticed that Emotion was causing unnecessary performance impact. cc @ellatrix |
Follow-up to #56524 (comment)