Skip to content

Commit bd5c158

Browse files
committed
perf(vapor): optimize cache property lookup
1 parent 263318d commit bd5c158

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

packages/runtime-vapor/src/apiCreateApp.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ import {
1919
} from '@vue/runtime-dom'
2020
import type { RawProps } from './componentProps'
2121
import { getGlobalThis } from '@vue/shared'
22+
import { optimizePropertyLookup } from './dom/prop'
2223

2324
let _createApp: CreateAppFunction<ParentNode, VaporComponent>
2425

2526
const mountApp: AppMountFn<ParentNode> = (app, container) => {
27+
optimizePropertyLookup()
28+
2629
// clear content before mounting
2730
if (container.nodeType === 1 /* Node.ELEMENT_NODE */) {
2831
container.textContent = ''

packages/runtime-vapor/src/dom/prop.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,22 @@ export function setDynamicProp(
244244
}
245245
return value
246246
}
247+
248+
let isOptimized = false
249+
250+
/**
251+
* Optimize property lookup for cache properties on Element and Text nodes
252+
*/
253+
export function optimizePropertyLookup(): void {
254+
if (isOptimized) return
255+
isOptimized = true
256+
const proto = Element.prototype as any
257+
proto.$evtclick = undefined
258+
proto.$root = false
259+
proto.$html =
260+
proto.$txt =
261+
proto.$cls =
262+
proto.$sty =
263+
(Text.prototype as any).$txt =
264+
''
265+
}

packages/runtime-vapor/src/vdomInterop.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
type App,
23
type ComponentInternalInstance,
34
type ConcreteComponent,
45
MoveType,
@@ -31,6 +32,7 @@ import { type RawProps, rawPropsProxyHandlers } from './componentProps'
3132
import type { RawSlots, VaporSlot } from './componentSlots'
3233
import { renderEffect } from './renderEffect'
3334
import { createTextNode } from './dom/node'
35+
import { optimizePropertyLookup } from './dom/prop'
3436

3537
// mounting vapor components and slots in vdom
3638
const vaporInteropImpl: Omit<
@@ -283,4 +285,9 @@ export const vaporInteropPlugin: Plugin = app => {
283285
vdomUnmount: internals.umt,
284286
vdomSlot: renderVDOMSlot.bind(null, internals),
285287
})
288+
const mount = app.mount
289+
app.mount = ((...args) => {
290+
optimizePropertyLookup()
291+
return mount(...args)
292+
}) satisfies App['mount']
286293
}

0 commit comments

Comments
 (0)