Skip to content

perf(button, theming): remove quadratic costs from the first render - #2598

Merged
rkaraivanov merged 1 commit into
masterfrom
rkaraivanov/first-render-quadratic-costs
Nov 12, 2026
Merged

rkaraivanov merged 1 commit into
masterfrom
rkaraivanov/first-render-quadratic-costs

Conversation

@rkaraivanov

Copy link
Copy Markdown
Member

Description

  • Read ElementInternals.labels only when a label can name the host (an id or an ancestor ). Each read creates a live list that the browser updates on every DOM change, so N form controls cost O(N²). The SSR DOM shim has no closest(), so the server skips it.
  • Keep the global theme listeners in a Set, not an EventTarget, which scans all listeners on each add and remove.
  • Chat: drop the unused ids of the message action buttons.

5,000 list items with a button: Chromium 31.4 s -> 0.8 s, Firefox 12.4 s -> 2.4 s, WebKit 5.3 s -> 1.9 s.

Type of Change

  • Refactoring (code improvements without functional changes)

Checklist

  • My code follows the project's coding standards
  • I have tested my changes locally

- Read ElementInternals.labels only when a label can name the host
  (an id or an ancestor <label>). Each read creates a live list that
  the browser updates on every DOM change, so N form controls cost
  O(N²). The SSR DOM shim has no closest(), so the server skips it.
- Keep the global theme listeners in a Set, not an EventTarget, which
  scans all listeners on each add and remove.
- Chat: drop the unused ids of the message action buttons.

5,000 list items with a button: Chromium 31.4 s -> 0.8 s, Firefox
12.4 s -> 2.4 s, WebKit 5.3 s -> 1.9 s.
@rkaraivanov
rkaraivanov merged commit e71dae0 into master Nov 12, 2026
10 checks passed
@rkaraivanov
rkaraivanov deleted the rkaraivanov/first-render-quadratic-costs branch November 12, 2026 16:25
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