Open ceari opened 4 years ago
Update: The extreme slow down issue was caused by many new empty media queries that appeared in the generated storyshots with our updates. After we managed to remove these again as described in https://github.com/styled-components/jest-styled-components/issues/276#issuecomment-618958757 the the performance is acceptable again because the number of regex matches in the while loop is limited.
However, I think this code could be optimized anyway.
Since we upgraded our project to styled-components v5 (5.1.0) and jest-styled-components from 6.3.3 to 7.0.2, Jest storyshots take a very long time to run.
I tracked the issue down to this line in the
extract
function inutils.js
: https://github.com/styled-components/jest-styled-components/blob/f8e6f79e70f0baae4906adb5d9762928c9438ac3/src/utils.js#L23getHTML()
is called repeatedly and callsmasterSheet.toString()
in our setup. This seems to be quite expensive leading to a lot of GC activity in NodeJS according to the profiler. AssuminggetHTML()
does not have side effects, it should be possible to callgetHTML()
only once withinextract
:Before:
After applying this fix locally:
Could you look into this please?