From 4bc9f39f028af7313e5cf24c16915a1985d27bf8 Mon Sep 17 00:00:00 2001 From: Evan You Date: Fri, 12 Apr 2024 11:49:31 +0800 Subject: [PATCH] perf(ssr): avoid calling markRaw on component instance proxy 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 | 3 +-- packages/runtime-core/src/componentPublicInstance.ts | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 2ad0a66f188..4cabdad0d44 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -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) } diff --git a/packages/runtime-core/src/componentPublicInstance.ts b/packages/runtime-core/src/componentPublicInstance.ts index 5b2b4f2303d..a1b45e4f9cc 100644 --- a/packages/runtime-core/src/componentPublicInstance.ts +++ b/packages/runtime-core/src/componentPublicInstance.ts @@ -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 = { get({ _: instance }: ComponentRenderContext, key: string) { + if (key === ReactiveFlags.SKIP) { + return true + } + const { ctx, setupState, data, props, accessCache, type, appContext } = instance