Skip to content

fix(ssr): perf tune-ups plus new benchmark suite - #7062

Merged
johnjenkins merged 3 commits into
v5from
fix/v5-ssr-perf
Nov 28, 2026
Merged

johnjenkins merged 3 commits into
v5from
fix/v5-ssr-perf

Conversation

@johnjenkins

@johnjenkins johnjenkins commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What is the current behavior?

GitHub Issue Number: N/A

  • The SSR platform is rebuilt for every render, so scoped CSS and ::part rewrites (scopeCss / expandPartSelectors) rerun for every component on every render. In scoped mode this dominated render time.
  • Every slotted node walks its host's whole internal tree to find its slot (findSlotFromSlottedNode > getHostSlotNodes), copying the result array at every level. A host with many slotted children costs O(children × tree).
  • insertBefore runs a closest() lookup for every slotted node even when nothing uses the result.
  • mock-doc's serializer is a recursive generator that yields hundreds of tiny strings, then joins them.
  • mock-doc attribute lookups go through a Proxy trap (in + isNaN) per property read and allocate a closure per find. children / childElementCount / firstElementChild build a filtered array on every access.
  • There is no SSR benchmark.

What is the new behavior?

Render speed. All HTML output is byte-identical to before.

  • Server-side style rewrites are cached per hydrate app, outside the per-render platform. The cache is capped at 1,000 style texts, since tag names in style text can change with a tag transformer.
  • Slot lookups are cached per host in a WeakMap. A cached slot is reused only while it is still connected inside the host with the same name; otherwise the full search runs. The search itself appends to one array.
  • The closest() lookup in insertBefore only runs when patchAll needs it.
  • The serializer writes into a single string buffer, and escaping skips strings with nothing to escape.
  • The attribute Proxy trap reads the property directly; lookups use loops. The child getters loop instead of filtering.

Benchmark. test/perf/ssr-benchmark is a 10-component, design-system-shaped app: large stylesheets, closest() context lookups, slots, shadow and scoped components. It renders fragment, list-50 and kitchen-sink pages in DSD and scoped mode.

  • pnpm test there reports median / p95 / first-render time, heap retained after GC and peak RSS.
  • benchmark-codspeed.mjs runs the same six cases as CodSpeed benchmarks (@codspeed/tinybench-plugin, simulation mode).

Median ms per render vs the previous build (11 interleaved rounds):

page DSD scoped
fragment +4.8% (1.6 ms, within noise) -73%
list-50 -13% -34%
kitchen-sink -14% -47%

Documentation

SSR benchmark, Node's --max-semi-space-size=16 cut peak RSS by ~47% (median +6-12%, p95 -9-15%).

Does this introduce a breaking change?

  • Yes
  • No

Testing

@johnjenkins
johnjenkins requested a review from a team as a code owner November 28, 2026 01:49
@codspeed

codspeed Bot commented Nov 28, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

🆕 6 new benchmarks
⏩ 2 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 ssr fragment (dsd) N/A 11.7 ms N/A
🆕 ssr fragment (scoped) N/A 12.7 ms N/A
🆕 ssr kitchen-sink (dsd) N/A 130.6 ms N/A
🆕 ssr kitchen-sink (scoped) N/A 161.4 ms N/A
🆕 ssr list-50 (dsd) N/A 492.9 ms N/A
🆕 ssr list-50 (scoped) N/A 569.1 ms N/A

Comparing fix/v5-ssr-perf (5cf880b) with v5 (3cd8ffc)

Open in CodSpeed

Footnotes

  1. 2 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@johnjenkins
johnjenkins merged commit 689f217 into v5 Nov 28, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant