Skip to content

perf(vapor): add fast path for static class names - #14803

Merged
edison1105 merged 4 commits into
minorfrom
edison/perf/setClass
May 11, 2026
Merged

edison1105 merged 4 commits into
minorfrom
edison/perf/setClass

Conversation

@edison1105

@edison1105 edison1105 commented May 11, 2026 •

Copy link
Copy Markdown
Member

Specialize simple class object and empty-string ternary bindings into flag-based setClassName calls, avoiding normalizeClass on the pure Vapor class hot path while preserving static class ordering and falling back for unsafe shapes.

Browser bench shows ~2.6x faster stable single-key ternary updates, ~9-21x faster stable single-key object updates depending on static base classes, ~30-37x faster stable multi-key object updates, and ~5-8x faster sparse multi-key churn.

Summary by CodeRabbit

  • Performance
    • Improved runtime performance for dynamic :class bindings through optimized code generation and efficient bitmask-based class handling.

Review Change Stack

Specialize simple class object and empty-string ternary bindings into flag-based setClassName calls, avoiding normalizeClass on the pure Vapor class hot path while preserving static class ordering and falling back for unsafe shapes.

Browser bench shows ~2.4x faster stable single-key ternary updates, ~9x faster stable single-key object updates, ~22-36x faster stable multi-key object updates, and ~5-7x faster sparse multi-key churn.

Co-authored-by: Copilot <[email protected]>
@coderabbitai

coderabbitai Bot commented May 11, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 86e694a6-6741-48e1-9b9e-b32e4e4d3da2

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.34% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a fast path optimization for static class names in the Vapor compiler, which is the core focus of all modifications.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch edison/perf/setClass

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

@edison1105 edison1105 added the scope: vapor related to vapor mode label May 11, 2026
@pkg-pr-new

pkg-pr-new Bot commented May 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14803
npm i https://pkg.pr.new/@vue/compiler-core@14803
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14803
npm i https://pkg.pr.new/@vue/compiler-dom@14803
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14803
npm i https://pkg.pr.new/@vue/compiler-sfc@14803
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14803
npm i https://pkg.pr.new/@vue/compiler-ssr@14803
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/compiler-vapor

pnpm add https://pkg.pr.new/@vue/compiler-vapor@14803
npm i https://pkg.pr.new/@vue/compiler-vapor@14803
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14803
npm i https://pkg.pr.new/@vue/reactivity@14803
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14803
npm i https://pkg.pr.new/@vue/runtime-core@14803
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14803
npm i https://pkg.pr.new/@vue/runtime-dom@14803
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/runtime-vapor

pnpm add https://pkg.pr.new/@vue/runtime-vapor@14803
npm i https://pkg.pr.new/@vue/runtime-vapor@14803
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14803
npm i https://pkg.pr.new/@vue/server-renderer@14803
yarn add https://pkg.pr.new/@vue/[email protected]

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14803
npm i https://pkg.pr.new/@vue/shared@14803
yarn add https://pkg.pr.new/@vue/[email protected]

vue

pnpm add https://pkg.pr.new/vue@14803
npm i https://pkg.pr.new/vue@14803
yarn add https://pkg.pr.new/[email protected]

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14803
npm i https://pkg.pr.new/@vue/compat@14803
yarn add https://pkg.pr.new/@vue/[email protected]

commit: 8f90304

@github-actions

github-actions Bot commented May 11, 2026 •

Copy link
Copy Markdown

Size Report

Bundles

File Size Gzip Brotli
compiler-dom.global.prod.js 86.5 kB 30.3 kB 26.6 kB
runtime-dom.global.prod.js 113 kB 42.6 kB 38.1 kB
vue.global.prod.js 172 kB 62.4 kB 55.6 kB

Usages

Name Size Gzip Brotli
createApp (CAPI only) 51.5 kB 20.1 kB 18.3 kB
createApp 60.5 kB 23.4 kB 21.3 kB
createApp + vaporInteropPlugin 103 kB (+83 B) 37.2 kB (+32 B) 33.5 kB (+56 B)
createVaporApp 27.5 kB (+83 B) 10.7 kB (+32 B) 9.8 kB (+22 B)
createSSRApp 65 kB 25.2 kB 22.9 kB
createVaporSSRApp 33.8 kB (+83 B) 12.8 kB (+29 B) 11.8 kB (+27 B)
defineCustomElement 67.1 kB 25.4 kB 23.1 kB
defineVaporCustomElement 40.3 kB (+83 B) 14.3 kB (+33 B) 13.2 kB (+72 B)
overall 75.8 kB 28.9 kB 26.2 kB

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
vite.config.ts (1)

91-113: ⚡ Quick win

Gate bench-browser behind an env flag or separate config.

The comment a few lines below already documents that Vitest initializes all projects even when --project filters them. Registering this browser benchmark project unconditionally means normal unit runs now pay the Playwright/browser-project startup cost. Browser instances are initialized as part of multi-project resolution and are not skipped by project filtering—they even use derived instance names (e.g., <project> (chromium)) that can bypass filter patterns. Mirror the VAPOR_E2E pattern here to avoid this overhead during typical development workflows.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@vite.config.ts` around lines 91 - 113, Gate the "bench-browser" Vitest
project registration behind an environment flag (reuse the existing VAPOR_E2E
pattern) so browser/playwright setup is only created when explicitly enabled;
specifically modify the object with name 'bench-browser' (the project that sets
browser.provider = playwright(...) and benchmark.include =
['packages/runtime-vapor/__tests__/bench/*.bench.ts']) to be conditionally added
to the projects array only when process.env.VAPOR_E2E (or a new flag) is truthy,
preventing unconditional Playwright/browser initialization during normal runs.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/runtime-vapor/src/dom/prop.ts`:
- Line 53: optimizePropertyLookup() currently predeclares $html, $cls and $sty
but not the new hot-path field $clsFlags introduced by setClassName(), which
forces an extra expando/shape transition; update optimizePropertyLookup() to
seed $clsFlags alongside $html/$cls/$sty so optimized elements allocate that
property in the shape up-front (add the $clsFlags predeclaration in the same
initialization block and any shape / sentinel logic that lists the optimized
props).

---

Nitpick comments:
In `@vite.config.ts`:
- Around line 91-113: Gate the "bench-browser" Vitest project registration
behind an environment flag (reuse the existing VAPOR_E2E pattern) so
browser/playwright setup is only created when explicitly enabled; specifically
modify the object with name 'bench-browser' (the project that sets
browser.provider = playwright(...) and benchmark.include =
['packages/runtime-vapor/__tests__/bench/*.bench.ts']) to be conditionally added
to the projects array only when process.env.VAPOR_E2E (or a new flag) is truthy,
preventing unconditional Playwright/browser initialization during normal runs.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: eb99856b-d1a3-4f00-91f7-0d5b451ca983

📥 Commits

Reviewing files that changed from the base of the PR and between 3212075 and e4ac8e6.

⛔ Files ignored due to path filters (3)
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap is excluded by !**/*.snap
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/vBind.spec.ts.snap is excluded by !**/*.snap
  • packages/compiler-vapor/__tests__/transforms/__snapshots__/vFor.spec.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (8)
  • packages/compiler-vapor/__tests__/transforms/vBind.spec.ts
  • packages/compiler-vapor/__tests__/transforms/vFor.spec.ts
  • packages/compiler-vapor/src/generators/prop.ts
  • packages/runtime-vapor/__tests__/bench/setClass.bench.ts
  • packages/runtime-vapor/__tests__/dom/prop.spec.ts
  • packages/runtime-vapor/src/dom/prop.ts
  • packages/runtime-vapor/src/index.ts
  • vite.config.ts

Comment thread packages/runtime-vapor/src/dom/prop.ts Resolved
@edison1105
edison1105 merged commit 1292bc4 into minor May 11, 2026
13 of 14 checks passed
@edison1105
edison1105 deleted the edison/perf/setClass branch May 11, 2026 09:30
zhiyuanzmj added a commit to vuejs/vue-jsx-vapor that referenced this pull request Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: vapor related to vapor mode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant