Skip to content

Commit 4bc9f39

Browse files
committed
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
1 parent 34106bc commit 4bc9f39

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Diff for: packages/runtime-core/src/component.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,7 @@ function setupStatefulComponent(
775775
// 0. create render proxy property access cache
776776
instance.accessCache = Object.create(null)
777777
// 1. create public instance / render proxy
778-
// also mark it raw so it's never observed
779-
instance.proxy = markRaw(new Proxy(instance.ctx, PublicInstanceProxyHandlers))
778+
instance.proxy = new Proxy(instance.ctx, PublicInstanceProxyHandlers)
780779
if (__DEV__) {
781780
exposePropsOnRenderContext(instance)
782781
}

Diff for: packages/runtime-core/src/componentPublicInstance.ts

+5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
isString,
2424
} from '@vue/shared'
2525
import {
26+
ReactiveFlags,
2627
type ShallowUnwrapRef,
2728
TrackOpTypes,
2829
type UnwrapNestedRefs,
@@ -307,6 +308,10 @@ const hasSetupBinding = (state: Data, key: string) =>
307308

308309
export const PublicInstanceProxyHandlers: ProxyHandler<any> = {
309310
get({ _: instance }: ComponentRenderContext, key: string) {
311+
if (key === ReactiveFlags.SKIP) {
312+
return true
313+
}
314+
310315
const { ctx, setupState, data, props, accessCache, type, appContext } =
311316
instance
312317

0 commit comments

Comments
 (0)