Skip to content

Investigating Significant Performance Discrepancy Between @emotion/react and @emotion/css #3332

@mbondyra

Description

@mbondyra

Hi Emotion team 👋

First off, thank you for your amazing work on Emotion. We’re long-time users at Elastic and really appreciate the flexibility and power the library offers.

We’re currently working on a large-scale migration from SCSS and styled-components to Emotion, and during performance investigations, we’ve uncovered significant and repeatable performance differences between @emotion/react and @emotion/css. The tests were run in Kibana using reproducible test cases, and later simplified into a CodeSandbox.

Summary of Findings

  1. @emotion/react renders significantly slower than @emotion/css.

  2. Memoizing styles improves performance with @emotion/css but has negligible (or sometimes negative) impact when using @emotion/react.

  3. Some optimizations (like moving conditionals outside of css) only benefit @emotion/css.

We suspect the root issue might be the lack of Emotion Babel plugin optimizations (e.g., caching), since Kibana currently includes both styled-components and Emotion, which may prevent us from using Emotion’s Babel plugin fully. Plus we cannot use babel plugin in codesandbox.

Questions

  1. Is this performance difference expected between @emotion/react and @emotion/css?

  2. Does the lack of the Babel plugin severely penalize @emotion/react performance? (even if using object syntax like we do)

  3. Are there known scenarios where @emotion/css should be preferred for performance-critical paths?

  4. Can @emotion/react be optimized in any way without dropping support for styled-components (which is still in our codebase)?

  5. Would you be open to profiling some of these examples or confirming if this is something Emotion itself could improve?

Repro Info
The idea of the app I wrote is simple – we show multiple scenarios on the page and render X components Y times. There's a radio list at the top of the page at the right, to choose between scenarios that render the same components using @emotion/css and @emotion/react.

CodeSandbox

The test case renders 2,000 components 3x across several strategies (inline, memoized, externalized, etc.), but the trends are visible with way less.

Here are some performance stats (at the bottom of the page) for @emotion/css:

Image

And for @emotion/react:

Image

Happy to provide more benchmarks, screenshots, or collaborate on further tests if it helps. This is quite impactful for us as we define best practices for Emotion usage at scale, and any help or clarity would be incredibly appreciated.

Thanks again!

Other examples:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions