-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Description
Performance bug
As Kibana devs migrate SCSS code into Emotion (meta issue), folks have begun to notice performance issues at runtime.
When a component renders with Emotion styles, a new <style> tag is added to the head. The effect is that style tags accumulate as we navigate Kibana.
Quote from @mbondyra:
Over time, this can result in thousands of redundant <style> tags, which resembles a memory leak and can impact runtime performance. The more we adopt the rewrite, the more this issue scales—more style tags keep getting added but never removed when navigating between pages. It also means other teams can unintentionally slow down our apps just by adding styles to theirs, since styles persist across navigation.
The investigation is still early at the time of this writing. In production, we're seeing styles being added with each plugin, not removed on unmount, but not being duplicated. Memoized components have their emotion style tags persisted. We're still looking into whether any styles are being duplicated. While going through several views we can reproduce 6900 style tags locally and the tab memory usage increased to 1.1GB.
Additional notes
- A resource which may help: https://engineering.deptagency.com/optimizing-emotion-in-react
- A live expression in devtools with
document.querySelectorAll('style').lengthand switching between views is a nice way to see what could inject duplicated style tags
