You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Performance degradation with tests and 6.3.x #5674
We recently upgraded our project to styled-components v6.3.x (currently at 6.3.9).
After doing so we noticed that our tests became drastically slower. We were able to isolate it to our dependency update to 6.3.9 and downgrading back to 6.2.0 resolved it.
What does SC_DISABLE_SPEEDY do? I noticed some tests were sporadically failing when I tried to upgrade an application to styled-components 6.3 and this workaround seems to fix the problem, but I'm curious why.
In speedy mode, styled-components injects styles using CSSOM APIs (e.g., inserting rules via the stylesheet) for performance. When you disable speedy mode, styled-components falls back to writing CSS text into <style> tags (more “DOM-visible”, generally slower, sometimes more compatible with edge cases).
Starting with 6.3.7 the numbers got closer to my published 6.3.9 results.
6.3.7 and 6.3.8 were pretty much the same. Maybe a tiny fraction slower than 6.3.9 but really close.
Given how 6.3.0 -> 6.3.6 worked with the test benchmark, I don't think it's worth running our full test suite with it. Just going with 6.3.9 (which is only a little slower than 6.2.0) it increased our full test suite time by 10+ minutes. I'm not sure I want to try it with something that is even slower.
[email protected] is published with additional fixes since prerelease.1, including the createGlobalStyle shared-group rearchitecture which changes how global style cleanup works.
If you're still seeing the ~25% regression vs 6.2.0 with prerelease.1, please re-test with prerelease.3: npm i [email protected]
Both prerelease.2 and prerelease.3 got signficantly worse. I couldn't even run my default benchmark because it takes too long (it iterates 10 times). Switching to 3 iterations came back with these results:
Just to make sure it wasn't my computer, I dropped back down to prerelease.1 and it came in at the normal 0.8/0.9 seconds or so (the usual 25% slower or so).
6.4.0-prerelease.6 is out with an additional fix for RSC style tag accumulation across HMR cycles (#5670, PR #5702). This shouldn't directly affect your jsdom test perf scenario (that was fixed in prerelease.4), but it eliminates another source of style accumulation in dev. npm i styled-components@test to try it.
6.4 includes the fix for this. The root cause was unbounded rule accumulation in createGlobalStyle under jsdom — each re-render appended rules without cleanup, causing O(n²) growth.
The fix rearchitects createGlobalStyle to use shared stylesheet groups with proper cleanup. In our benchmarks this was a 375x improvement in the jsdom test path.
Please upgrade and confirm the improvement on your end. Thanks for the detailed reproduction — it was instrumental in isolating the problem.
Activity
spdaley commentedon Mar 5, 2026
We've been able to work around this by adding the following to a jest setup file:
aelfric commentedon Mar 9, 2026
What does
SC_DISABLE_SPEEDYdo? I noticed some tests were sporadically failing when I tried to upgrade an application to styled-components 6.3 and this workaround seems to fix the problem, but I'm curious why.khitrenovich commentedon Mar 9, 2026
In speedy mode, styled-components injects styles using CSSOM APIs (e.g., inserting rules via the stylesheet) for performance. When you disable speedy mode, styled-components falls back to writing CSS text into
<style>tags (more “DOM-visible”, generally slower, sometimes more compatible with edge cases).quantizor commentedon Mar 13, 2026
That's a big version range, can you bisect?
spdaley commentedon Mar 13, 2026
Based on my test repo
6.3.0 -> 6.3.6 were way worse
The test benchmark was seeing results in this range:
Starting with 6.3.7 the numbers got closer to my published 6.3.9 results.
6.3.7 and 6.3.8 were pretty much the same. Maybe a tiny fraction slower than 6.3.9 but really close.
Given how 6.3.0 -> 6.3.6 worked with the test benchmark, I don't think it's worth running our full test suite with it. Just going with 6.3.9 (which is only a little slower than 6.2.0) it increased our full test suite time by 10+ minutes. I'm not sure I want to try it with something that is even slower.
quantizor commentedon Mar 13, 2026
Thank you, will follow up.
perf: fix createGlobalStyle test performance regression
perf: fix createGlobalStyle test performance regression (styled-compo…
quantizor commentedon Mar 19, 2026
This fix is available in
[email protected]. Please try it and report any issues:spdaley commentedon Mar 19, 2026
I tried that release using my test harness I attached in the description and it didn't seem to help it at all:
It's similar timings as 6.3.11 (and .12 as well).
perf: skip effect re-runs for static createGlobalStyle
quantizor commentedon Mar 19, 2026
Try
[email protected]2 remaining items
quantizor commentedon Mar 21, 2026
[email protected]is published with additional fixes since prerelease.1, including thecreateGlobalStyleshared-group rearchitecture which changes how global style cleanup works.If you're still seeing the ~25% regression vs 6.2.0 with
prerelease.1, please re-test withprerelease.3:npm i [email protected]See Version Packages PR #5687 for the full changelog.
spdaley commentedon Mar 21, 2026
Both prerelease.2 and prerelease.3 got signficantly worse. I couldn't even run my default benchmark because it takes too long (it iterates 10 times). Switching to 3 iterations came back with these results:
Just to make sure it wasn't my computer, I dropped back down to prerelease.1 and it came in at the normal 0.8/0.9 seconds or so (the usual 25% slower or so).
quantizor commentedon Mar 21, 2026
Ok, I'll spend some time this weekend in your repro directly.
fix: prevent createGlobalStyle style accumulation in jsdom test envir…
test: add regression test for GlobalStyle rule accumulation (#5674)
test: add regression test for GlobalStyle rule accumulation (#5674)
quantizor commentedon Mar 21, 2026
@spdaley ok I think I got it in
6.4.0-prerelease.4, also thank you so much for helping with this. Your repro was super helpful!fix: prevent createGlobalStyle style accumulation in jsdom test envir…
spdaley commentedon Mar 23, 2026
That looks good. I validated with my test harness and I also ran our full test suite with that version and that seemed good as well too. thanks.
quantizor commentedon Mar 23, 2026
Fantastic. Chasing down a few other bugs I'm noticing on a second harness, probably 1-2 more RCs.
quantizor commentedon Mar 24, 2026
6.4.0-prerelease.6is out with an additional fix for RSC style tag accumulation across HMR cycles (#5670, PR #5702). This shouldn't directly affect your jsdom test perf scenario (that was fixed in prerelease.4), but it eliminates another source of style accumulation in dev.npm i styled-components@testto try it.quantizor commentedon Apr 9, 2026
6.4 includes the fix for this. The root cause was unbounded rule accumulation in
createGlobalStyleunder jsdom — each re-render appended rules without cleanup, causing O(n²) growth.The fix rearchitects
createGlobalStyleto use shared stylesheet groups with proper cleanup. In our benchmarks this was a 375x improvement in the jsdom test path.Please upgrade and confirm the improvement on your end. Thanks for the detailed reproduction — it was instrumental in isolating the problem.