]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
perf(ssr): avoid calling markRaw on component instance proxy
authorEvan You <yyx990803@gmail.com>
Fri, 12 Apr 2024 03:49:31 +0000 (11:49 +0800)
committerEvan You <yyx990803@gmail.com>
Fri, 12 Apr 2024 03:49:45 +0000 (11:49 +0800)
The previous behavior invokes the definePropery proxy trap on the
instance proxy and has massive overhead. This change improves Vue
ops/sec by 40% in https://github.com/eknkc/ssr-benchmark

packages/runtime-core/src/component.ts
packages/runtime-core/src/componentPublicInstance.ts

index 2ad0a66f188d2ded68f6fd695064c11311df012e..4cabdad0d44ad6c0952b07a457f2de39f92a84ee 100644 (file)
@@ -775,8 +775,7 @@ function setupStatefulComponent(
   // 0. create render proxy property access cache
   instance.accessCache = Object.create(null)
   // 1. create public instance / render proxy
-  // also mark it raw so it's never observed
-  instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers))
+  instance.proxy = new Proxy(instance.ctx, PublicInstanceProxyHandlers)
   if (__DEV__) {
     exposePropsOnRenderContext(instance)
   }
index 5b2b4f2303d52650efdd18d5189948e7930caae2..a1b45e4f9cce57f93461a3ea9f825fe3910d3d58 100644 (file)
@@ -23,6 +23,7 @@ import {
   isString,
 } from '@vue/shared'
 import {
+  ReactiveFlags,
   type ShallowUnwrapRef,
   TrackOpTypes,
   type UnwrapNestedRefs,
@@ -307,6 +308,10 @@ const hasSetupBinding = (state: Data, key: string) =>
 
 export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
   get({ _: instance }: ComponentRenderContext, key: string) {
+    if (key === ReactiveFlags.SKIP) {
+      return true
+    }
+
     const { ctx, setupState, data, props, accessCache, type, appContext } =
       instance