From: Evan You Date: Mon, 10 Feb 2025 08:27:13 +0000 (+0800) Subject: perf(vapor): optimize cache property lookup X-Git-Tag: v3.6.0-alpha.1~16^2~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd5c1583b7f311a680d61259c6cbd1b1055d28c5;p=thirdparty%2Fvuejs%2Fcore.git perf(vapor): optimize cache property lookup --- diff --git a/packages/runtime-vapor/src/apiCreateApp.ts b/packages/runtime-vapor/src/apiCreateApp.ts index 9c77279ac4..8088e1aee6 100644 --- a/packages/runtime-vapor/src/apiCreateApp.ts +++ b/packages/runtime-vapor/src/apiCreateApp.ts @@ -19,10 +19,13 @@ import { } from '@vue/runtime-dom' import type { RawProps } from './componentProps' import { getGlobalThis } from '@vue/shared' +import { optimizePropertyLookup } from './dom/prop' let _createApp: CreateAppFunction const mountApp: AppMountFn = (app, container) => { + optimizePropertyLookup() + // clear content before mounting if (container.nodeType === 1 /* Node.ELEMENT_NODE */) { container.textContent = '' diff --git a/packages/runtime-vapor/src/dom/prop.ts b/packages/runtime-vapor/src/dom/prop.ts index aae3948de6..137f2d807f 100644 --- a/packages/runtime-vapor/src/dom/prop.ts +++ b/packages/runtime-vapor/src/dom/prop.ts @@ -244,3 +244,22 @@ export function setDynamicProp( } return value } + +let isOptimized = false + +/** + * Optimize property lookup for cache properties on Element and Text nodes + */ +export function optimizePropertyLookup(): void { + if (isOptimized) return + isOptimized = true + const proto = Element.prototype as any + proto.$evtclick = undefined + proto.$root = false + proto.$html = + proto.$txt = + proto.$cls = + proto.$sty = + (Text.prototype as any).$txt = + '' +} diff --git a/packages/runtime-vapor/src/vdomInterop.ts b/packages/runtime-vapor/src/vdomInterop.ts index 68cb00956f..77228fd72a 100644 --- a/packages/runtime-vapor/src/vdomInterop.ts +++ b/packages/runtime-vapor/src/vdomInterop.ts @@ -1,4 +1,5 @@ import { + type App, type ComponentInternalInstance, type ConcreteComponent, MoveType, @@ -31,6 +32,7 @@ import { type RawProps, rawPropsProxyHandlers } from './componentProps' import type { RawSlots, VaporSlot } from './componentSlots' import { renderEffect } from './renderEffect' import { createTextNode } from './dom/node' +import { optimizePropertyLookup } from './dom/prop' // mounting vapor components and slots in vdom const vaporInteropImpl: Omit< @@ -283,4 +285,9 @@ export const vaporInteropPlugin: Plugin = app => { vdomUnmount: internals.umt, vdomSlot: renderVDOMSlot.bind(null, internals), }) + const mount = app.mount + app.mount = ((...args) => { + optimizePropertyLookup() + return mount(...args) + }) satisfies App['mount'] }