possible styled-component v4 performance issues?
See original GitHub issueI’m not sure what is going on, but just for the fact that I’m rendering 1000 boxes using styled components my screen takes almost a second to render, when using regular divs it takes less than 100ms.
Environment
System:
- OS: macOS 10.14.1
- CPU: (8) x64 Intel® Core™ i7-7820HQ CPU @ 2.90GHz
- Memory: 731.01 MB / 16.00 GB
- Shell: 3.2.57 - /bin/bash
Binaries:
- Node: 8.12.0 - /usr/local/bin/node
- Yarn: 1.10.1 - /usr/local/bin/yarn
- npm: 6.4.1 - /usr/local/bin/npm
npmPackages:
- babel-plugin-styled-components: ^1.6.4 => 1.8.0
- styled-components: ^4.0.0 => 4.0.3
Reproduction
https://codesandbox.io/s/xv1rz10p8q
Steps to reproduce
- Open sandbox link
- Notice that by default I’m not using styled components.
- Click on “show boxes”
- Notice that it is basically instant rendering (around 80ms)
- Swap from
App
toApp2
that uses styled-components - Notice that the rendering time now is not instant (around ~600ms)
The progression seems to be exponential. For example, 10000 boxes with styled-components takes 6 seconds, without 600ms.
Expected Behavior
I’m not sure if I’m doing something wrong, or if my expectations are wrong. But I’m hoping the performance will be similar.
Actual Behavior
The performance is quite different when including even a very simplistic styled-component div
Issue Analytics
- State:
- Created 5 years ago
- Comments:27 (17 by maintainers)
Top Results From Across the Web
FAQs - styled-components
If the styles are changed using interpolations, like <Button secondary />, then the dynamic class will be a different one, while the static...
Read more >Performance issues with styled components - Stack Overflow
When doing some React profiling on my Chrome DevTools, I see some styled components taking up to 100ms to run.
Read more >A 55% Performance Improvement Upgrading Material-UI from ...
This post comes from our engineering team and details how upgrading our core UI library resulted in some awesome performance improvements!
Read more >Measuring React styled-components performance & best ...
Learn how to measure the performance of your React styled-components and implement best practices to keep your code concise and efficient.
Read more >Announcing styled-components v4: Better, Faster, Stronger
We're very excited to announce that styled-components v4 is officially in beta ... which means performance is officially no longer an issue!
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@demian85
styled-components
needs to consume the stylesheet instance to add a component’s styles to the stylesheet, and contexts are the canonical way to pass a global object (in this case the stylesheet) to React components.Maybe in the future, when hooks are stable,
Context.Consumer
s could be replaced byuseContext
, to avoid React tree pollution.There’s probably not much we can do to fix that performance hit for the styled-components side unfortunately, it’s on the React team to improve it 😢