Skip to content

Performance degradation with tests and 6.3.x #5674

Description

@spdaley

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.

Working with codex, I was able to create a smallish repo with a benchmark test that seems to confirm the performance issue.
The repo can be found at https://github.com/spdaley/styled-components-jest-repro

To run it you would do:

  1. yarn install (we use yarn v1)
  2. yarn set:sc:620
  3. yarn bench:compare (to get a benchmark for 6.2.0)
  4. yarn set:sc:639
  5. yarn bench:compare (to get a benchmark for 6.3.9)

The benchmark does two things:

  1. It runs the test 10 times and grabs the timings for each run and gets some stats for those timings.
  2. It then re-runs the test 10 times but with createGlobalStyle mocked to a no-op
  3. It then compares the times

On my laptop (Macbook pro running Sequoia) I got the following times (fairly consistently within a % or so each time I ran)

  • For 6.2.0
baseline
  runs: 10
  median: 0.741s
  min: 0.726s
  max: 1.258s

SC_DISABLE_GLOBAL_STYLE_MOCK=1
  runs: 10
  median: 0.725s
  min: 0.715s
  max: 0.767s

median delta: 0.016s (2.1%)
  • For 6.3.9
baseline
  runs: 10
  median: 0.976s
  min: 0.964s
  max: 1.435s

SC_DISABLE_GLOBAL_STYLE_MOCK=1
  runs: 10
  median: 0.730s
  min: 0.723s
  max: 0.748s

median delta: 0.246s (25.2%)

On my laptop, we are seeing about a 25% performance degradation in that test when using 6.3.9.

Any help on this would be greatly appreciated. Maybe there is something we are doing wrong that we should be doing with 6.3.x now?
Thanks.

Activity

  1. spdaley commented on Mar 5, 2026

    @spdaley
    Author

    We've been able to work around this by adding the following to a jest setup file:

    if (typeof globalThis.SC_DISABLE_SPEEDY === 'undefined') {
      globalThis.SC_DISABLE_SPEEDY = false;
    }
    
  2. aelfric commented on Mar 9, 2026

    @aelfric

    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.

  3. khitrenovich commented on Mar 9, 2026

    @khitrenovich

    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).

  4. quantizor commented on Mar 13, 2026

    @quantizor
    Contributor

    That's a big version range, can you bisect?

  5. spdaley commented on Mar 13, 2026

    @spdaley
    Author

    Based on my test repo
    6.3.0 -> 6.3.6 were way worse

    The test benchmark was seeing results in this range:

    baseline
      runs: 10
      median: 9.018s
      min: 8.878s
      max: 9.180s
    
    SC_DISABLE_GLOBAL_STYLE_MOCK=1
      runs: 10
      median: 0.720s
      min: 0.710s
      max: 0.726s
    

    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.

  6. quantizor commented on Mar 13, 2026

    @quantizor
    Contributor

    Thank you, will follow up.

  7. self-assigned this
    on Mar 13, 2026
  8. added a commit that references this issue on Mar 19, 2026
    ff23908
  9. added a commit that references this issue on Mar 19, 2026
    db4f940
  10. quantizor commented on Mar 19, 2026

    @quantizor
    Contributor

    This fix is available in [email protected]. Please try it and report any issues:

    npm install [email protected]
    
  11. spdaley commented on Mar 19, 2026

    @spdaley
    Author

    I tried that release using my test harness I attached in the description and it didn't seem to help it at all:

    % yarn bench:compare
    yarn run v1.22.22
    $ node ./scripts/benchmark.cjs --compare
    
    baseline
      runs: 10
      median: 0.877s
      min: 0.862s
      max: 1.149s
    
    SC_DISABLE_GLOBAL_STYLE_MOCK=1
      runs: 10
      median: 0.640s
      min: 0.635s
      max: 0.651s
    
    median delta: 0.237s (27.0%)
    

    It's similar timings as 6.3.11 (and .12 as well).

  12. quantizor commented on Mar 19, 2026

    @quantizor
    Contributor
  13. 2 remaining items

  14. quantizor commented on Mar 21, 2026

    @quantizor
    Contributor

    [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]

    See Version Packages PR #5687 for the full changelog.

  15. spdaley commented on Mar 21, 2026

    @spdaley
    Author

    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:

    % BENCH_ITERATIONS=3 yarn bench:compare
    yarn run v1.22.22
    $ node ./scripts/benchmark.cjs --compare
    
    baseline
      runs: 3
      median: 56.471s
      min: 56.273s
      max: 57.012s
    
    SC_DISABLE_GLOBAL_STYLE_MOCK=1
      runs: 3
      median: 0.667s
      min: 0.661s
      max: 0.918s
    

    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).

  16. quantizor commented on Mar 21, 2026

    @quantizor
    Contributor

    Ok, I'll spend some time this weekend in your repro directly.

  17. added 2 commits that reference this issue on Mar 21, 2026
    343c852
    0a255c7
  18. quantizor commented on Mar 21, 2026

    @quantizor
    Contributor

    @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!

  19. added a commit that references this issue on Mar 21, 2026
    8f338ca
  20. spdaley commented on Mar 23, 2026

    @spdaley
    Author

    @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!

    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.

  21. quantizor commented on Mar 23, 2026

    @quantizor
    Contributor

    Fantastic. Chasing down a few other bugs I'm noticing on a second harness, probably 1-2 more RCs.

  22. quantizor commented on Mar 24, 2026

    @quantizor
    Contributor

    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.

  23. quantizor commented on Apr 9, 2026

    @quantizor
    Contributor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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