Skip to content

perf(reactivity): skip type checks for cached proxies#14860

Merged
edison1105 merged 1 commit into
vuejs:mainfrom
dhimasardinata:perf/reactivity-cached-proxy
May 27, 2026
Merged

perf(reactivity): skip type checks for cached proxies#14860
edison1105 merged 1 commit into
vuejs:mainfrom
dhimasardinata:perf/reactivity-cached-proxy

Conversation

@dhimasardinata

@dhimasardinata dhimasardinata commented May 19, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Check the existing proxy cache before computing the target raw type in createReactiveObject.
  • Preserve the markRaw / non-extensible early return before the cache lookup.
  • Add benchmarks for cached reactive objects and nested reactive property access.

Test Plan

  • pnpm exec vitest run --project=unit packages/reactivity/tests/reactive.spec.ts
  • pnpm exec prettier --check packages/reactivity/src/reactive.ts packages/reactivity/benchmarks/reactiveObject.bench.ts
  • pnpm exec eslint packages/reactivity/src/reactive.ts packages/reactivity/benchmarks/reactiveObject.bench.ts
  • pnpm run prebench
  • pnpm exec vitest bench --project=unit packages/reactivity/benchmarks/reactiveObject.bench.ts --outputJson=/tmp/vue-patched-nested-reactiveObject.json

Representative local benchmark run after the latest change:

  • return cached reactive obj: 3.46M hz
  • read nested reactive obj property: 1.60M hz

@coderabbitai

coderabbitai Bot commented May 19, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

This PR refactors proxy-type detection in createReactiveObject (replace getTargetType with targetTypeMap) and adds benchmarks for cached reactive reuse and nested reactive property access.

Changes

Reactive Object Proxy Refactoring

Layer / File(s) Summary
Simplify proxy-type detection helper
packages/reactivity/src/reactive.ts
Replace getTargetType() with targetTypeMap(rawType) helper. Update createReactiveObject to early-return for ReactiveFlags.SKIP and non-extensible targets, check proxyMap for existing proxies, then compute targetType and decide proxy creation.
Benchmark reactive object caching and nested access
packages/reactivity/__benchmarks__/reactiveObject.bench.ts
Add benchmarks measuring cached proxy reuse (second reactive(raw) call on same object), top-level reactive property reads, and nested reactive property reads.

Sequence Diagram(s)

sequenceDiagram
  participant BenchRunner
  participant reactive
  participant createReactiveObject
  participant proxyMap
  participant targetTypeMap
  BenchRunner->>reactive: call reactive(raw)
  reactive->>createReactiveObject: forward target
  createReactiveObject->>proxyMap: lookup existing proxy
  createReactiveObject->>targetTypeMap: compute target type if needed
  createReactiveObject-->>reactive: return proxy (cached or new)
  BenchRunner->>reactive: call reactive(raw) again (cached path)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

I’m a rabbit in the code so spry,
Caching proxies as they fly.
Nested bunnies, hops so neat,
Refactors tidy, benchmarks meet. 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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 accurately describes the main optimization: skipping type checks for cached proxies in the reactivity module.
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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@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

🤖 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/reactivity/__benchmarks__/reactiveObject.bench.ts`:
- Around line 25-27: The benchmark labeled "read nested reactive obj property"
is only accessing r.a but should exercise a nested access; update the bench body
(the callback passed to bench) to read the nested property (e.g., r.a.b) instead
of just r.a so the benchmark measures the nested path—modify the callback that
currently references r.a to access r.a.b (or the appropriate nested key on r) in
the bench invocation.
🪄 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: 7096b990-7671-4011-96a7-511e8cd94516

📥 Commits

Reviewing files that changed from the base of the PR and between 1ce598e and 6d17709.

📒 Files selected for processing (2)
  • packages/reactivity/__benchmarks__/reactiveObject.bench.ts
  • packages/reactivity/src/reactive.ts

Comment thread packages/reactivity/__benchmarks__/reactiveObject.bench.ts
@dhimasardinata dhimasardinata force-pushed the perf/reactivity-cached-proxy branch from 6d17709 to bc25d3d Compare May 19, 2026 15:04
@pkg-pr-new

pkg-pr-new Bot commented May 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vue/compiler-core

pnpm add https://pkg.pr.new/@vue/compiler-core@14860
npm i https://pkg.pr.new/@vue/compiler-core@14860
yarn add https://pkg.pr.new/@vue/compiler-core@14860.tgz

@vue/compiler-dom

pnpm add https://pkg.pr.new/@vue/compiler-dom@14860
npm i https://pkg.pr.new/@vue/compiler-dom@14860
yarn add https://pkg.pr.new/@vue/compiler-dom@14860.tgz

@vue/compiler-sfc

pnpm add https://pkg.pr.new/@vue/compiler-sfc@14860
npm i https://pkg.pr.new/@vue/compiler-sfc@14860
yarn add https://pkg.pr.new/@vue/compiler-sfc@14860.tgz

@vue/compiler-ssr

pnpm add https://pkg.pr.new/@vue/compiler-ssr@14860
npm i https://pkg.pr.new/@vue/compiler-ssr@14860
yarn add https://pkg.pr.new/@vue/compiler-ssr@14860.tgz

@vue/reactivity

pnpm add https://pkg.pr.new/@vue/reactivity@14860
npm i https://pkg.pr.new/@vue/reactivity@14860
yarn add https://pkg.pr.new/@vue/reactivity@14860.tgz

@vue/runtime-core

pnpm add https://pkg.pr.new/@vue/runtime-core@14860
npm i https://pkg.pr.new/@vue/runtime-core@14860
yarn add https://pkg.pr.new/@vue/runtime-core@14860.tgz

@vue/runtime-dom

pnpm add https://pkg.pr.new/@vue/runtime-dom@14860
npm i https://pkg.pr.new/@vue/runtime-dom@14860
yarn add https://pkg.pr.new/@vue/runtime-dom@14860.tgz

@vue/server-renderer

pnpm add https://pkg.pr.new/@vue/server-renderer@14860
npm i https://pkg.pr.new/@vue/server-renderer@14860
yarn add https://pkg.pr.new/@vue/server-renderer@14860.tgz

@vue/shared

pnpm add https://pkg.pr.new/@vue/shared@14860
npm i https://pkg.pr.new/@vue/shared@14860
yarn add https://pkg.pr.new/@vue/shared@14860.tgz

vue

pnpm add https://pkg.pr.new/vue@14860
npm i https://pkg.pr.new/vue@14860
yarn add https://pkg.pr.new/vue@14860.tgz

@vue/compat

pnpm add https://pkg.pr.new/@vue/compat@14860
npm i https://pkg.pr.new/@vue/compat@14860
yarn add https://pkg.pr.new/@vue/compat@14860.tgz

commit: bc25d3d

@edison1105

Copy link
Copy Markdown
Member

/ecosystem-ci run

@vue-bot

vue-bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

📝 Ran ecosystem CI: Open

suite result latest scheduled
radix-vue success success
language-tools success success
vant success success
router failure success
pinia success success
vue-i18n success success
primevue success success
vitepress success success
vite-plugin-vue success success
test-utils success success
nuxt failure failure
vue-simple-compiler success success
vueuse success success
vue-macros success success
vuetify success success
quasar failure failure

@edison1105 edison1105 added ready to merge The PR is ready to be merged. 🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. labels May 26, 2026
@edison1105 edison1105 merged commit 5734fe9 into vuejs:main May 27, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🍰 p2-nice-to-have Priority 2: this is not breaking anything but nice to have it addressed. ready to merge The PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants