Skip to content

bug: serializeShadowRoot: 'scoped' has a massive performance degradation. #6226

@Armand-Lluka

Description

@Armand-Lluka

Prerequisites

Stencil Version

4.27.1

Current Behavior

Currently, when using serializeShadowRoot: 'scoped' to SSR render, there is a huge degradation in terms of parsing speed of the CSS. A single component, with many css classes attached to it, is taking around 16s to render using serializeShadowRoot: 'scoped'. This seems to be growing linearly with the amount of unique components used, as well as the amount of CSS these components contain.

From some local testing, it seems that the biggest culprit here is how the CSS being parsed in styles.ts or shadow-css.ts. I know that in the past there was a refactoring in how things work when moving things away from "scoped" parsing, so perhaps something was lost when it was re-introduced recently by @johnjenkins?

Expected Behavior

The performance should be the same for both DSD and Scoped versions, similar to how things were in the past.

System Info

System: node 20.18.3
Platform: darwin (24.3.0)
CPU Model: Apple M1 Pro (8 cpus)
Compiler: stencil-bug-reproduction/node_modules/@stencil/core/compiler/stencil.js
Build: 1741890846
Stencil: 4.28.2 🎤
TypeScript: 5.5.4
Rollup: 4.34.9
Parse5: 7.2.1
jQuery: 4.0.0-pre
Terser: 5.37.0

Steps to Reproduce

  1. npm i
  2. npm run build
  3. npm run serve to spin up server
  4. Visit http://localhost:8090/
  5. Observe the time it takes to render.
  6. Remove component css classes, run npm run build && npm run serve and notice that with fewer/no classes the performance improves.

Code Reproduction URL

https://github.com/Armand-Lluka/stencil-bug-reproductions/tree/renderToString-performance-example

Additional Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug: ValidatedThis PR or Issue is verified to be a bug within StencilHelp Wanted

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions