Skip to content

Commit 629ee75

Browse files
committed
perf: prevent renderer hot functions being inlined by minifiers
Terser will aggressively inline hot functions in renderer.ts in order to reduce "function" declarations, but the inlining leads to performance overhead (small, but noticeable in benchmarks). Since we cannot control user's minifier options, we have to avoid the deopt in the source code by using arrow functions in hot paths.
1 parent f71a50a commit 629ee75

File tree

2 files changed

+74
-73
lines changed

2 files changed

+74
-73
lines changed

packages/runtime-core/src/hydration.ts

+9-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ComponentInternalInstance } from './component'
1212
import { invokeDirectiveHook } from './directives'
1313
import { warn } from './warning'
1414
import { PatchFlags, ShapeFlags, isReservedProp, isOn } from '@vue/shared'
15+
import { RendererOptions } from './renderer'
1516

1617
// Note: hydration is DOM-specific
1718
// But we have to place it in core due to tight coupling with core - splitting
@@ -20,9 +21,9 @@ import { PatchFlags, ShapeFlags, isReservedProp, isOn } from '@vue/shared'
2021
// passed in via arguments.
2122
export function createHydrationFunctions(
2223
mountComponent: any, // TODO
23-
patchProp: any // TODO
24+
patchProp: RendererOptions['patchProp']
2425
) {
25-
function hydrate(vnode: VNode, container: Element) {
26+
const hydrate = (vnode: VNode, container: Element) => {
2627
if (__DEV__ && !container.hasChildNodes()) {
2728
warn(`Attempting to hydrate existing markup but container is empty.`)
2829
return
@@ -34,11 +35,11 @@ export function createHydrationFunctions(
3435
// TODO handle mismatches
3536
// TODO SVG
3637
// TODO Suspense
37-
function hydrateNode(
38+
const hydrateNode = (
3839
node: Node,
3940
vnode: VNode,
4041
parentComponent: ComponentInternalInstance | null = null
41-
): Node | null | undefined {
42+
): Node | null | undefined => {
4243
const { type, shapeFlag } = vnode
4344
vnode.el = node
4445
switch (type) {
@@ -73,11 +74,11 @@ export function createHydrationFunctions(
7374
}
7475
}
7576

76-
function hydrateElement(
77+
const hydrateElement = (
7778
el: Element,
7879
vnode: VNode,
7980
parentComponent: ComponentInternalInstance | null
80-
) {
81+
) => {
8182
const { props, patchFlag } = vnode
8283
// skip props & children if this is hoisted static nodes
8384
if (patchFlag !== PatchFlags.HOISTED) {
@@ -124,11 +125,11 @@ export function createHydrationFunctions(
124125
return el.nextSibling
125126
}
126127

127-
function hydrateChildren(
128+
const hydrateChildren = (
128129
node: Node | null | undefined,
129130
vnodes: VNode[],
130131
parentComponent: ComponentInternalInstance | null
131-
): Node | null | undefined {
132+
): Node | null | undefined => {
132133
for (let i = 0; node != null && i < vnodes.length; i++) {
133134
// TODO can skip normalizeVNode in optimized mode
134135
// (need hint on rendered markup?)

0 commit comments

Comments
 (0)