Skip to content

Commit e5e6ee5

Browse files
committed
test: add hydration benchmark for Vapor and VDOM
1 parent 0dc8963 commit e5e6ee5

File tree

1 file changed

+225
-0
lines changed

1 file changed

+225
-0
lines changed
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
/**
2+
* @vitest-environment jsdom
3+
*/
4+
import { bench, describe } from 'vitest'
5+
import {
6+
ssrInterpolate as _ssrInterpolate,
7+
ssrRenderAttrs as _ssrRenderAttrs,
8+
} from '@vue/server-renderer'
9+
import {
10+
Fragment as _Fragment,
11+
createBlock as _createBlock,
12+
createCommentVNode as _createCommentVNode,
13+
createElementBlock as _createElementBlock,
14+
createElementVNode as _createElementVNode,
15+
createVNode as _createVNode,
16+
openBlock as _openBlock,
17+
renderList as _renderList,
18+
renderSlot as _renderSlot,
19+
toDisplayString as _toDisplayString,
20+
vModelText as _vModelText,
21+
withCtx as _withCtx,
22+
withDirectives as _withDirectives,
23+
createSSRApp,
24+
ref,
25+
} from '@vue/runtime-dom'
26+
import {
27+
applyTextModel as _applyTextModel,
28+
child as _child,
29+
createComponent as _createComponent,
30+
createFor as _createFor,
31+
createIf as _createIf,
32+
createSlot as _createSlot,
33+
next as _next,
34+
renderEffect as _renderEffect,
35+
setInsertionState as _setInsertionState,
36+
setText as _setText,
37+
template as _template,
38+
createVaporSSRApp,
39+
} from '@vue/runtime-vapor'
40+
41+
describe('hydration benchmark', () => {
42+
{
43+
let html = `<div><div><h1>Hello World!</h1><input value="Hello World!"><div><!--[--><div>1</div><div>2</div><div>3</div><div>4</div><div>5</div><!--]--></div><!--[--><!--]--><span></span></div></div>`
44+
45+
const t0 = _template('<h1> </h1>')
46+
const t1 = _template('<div> </div>')
47+
const t2 = _template('<div><input><div></div><!><span></span></div>', true)
48+
49+
const VaporChild = {
50+
__vapor: true,
51+
setup() {
52+
const msg = ref('Hello World!')
53+
const show = ref(true)
54+
55+
const n9 = t2() as any
56+
const n0 = _child(n9) as any
57+
const n8 = _next(n0) as any
58+
const n7 = _next(n8) as any
59+
_setInsertionState(n9, n8)
60+
_createIf(
61+
() => show.value,
62+
() => {
63+
const n3 = t0() as any
64+
_applyTextModel(
65+
n3,
66+
() => msg.value,
67+
_value => (msg.value = _value),
68+
)
69+
return n3
70+
},
71+
)
72+
_setInsertionState(n7)
73+
_createFor(
74+
() => 5,
75+
_for_item0 => {
76+
const n6 = t1() as any
77+
const x6 = _child(n6) as any
78+
_renderEffect(() =>
79+
_setText(x6, _toDisplayString(_for_item0.value)),
80+
)
81+
return n6
82+
},
83+
undefined,
84+
5,
85+
)
86+
const x0 = _child(n0) as any
87+
_renderEffect(() => _setText(x0, _toDisplayString(msg.value)))
88+
return n9
89+
},
90+
}
91+
92+
const tt0 = _template('<span> </span>')
93+
const tt1 = _template('<div></div>', true)
94+
95+
const VaporApp = {
96+
__vapor: true,
97+
setup() {
98+
const msg = ref('hi')
99+
const n2 = tt1() as any
100+
_setInsertionState(n2)
101+
_createComponent(VaporChild, null, {
102+
default: () => {
103+
const n0 = tt0() as any
104+
const x0 = _child(n0) as any
105+
_renderEffect(() => _setText(x0, _toDisplayString(msg.value)))
106+
return n0
107+
},
108+
})
109+
return n2
110+
},
111+
}
112+
113+
const VdomChild = {
114+
setup() {
115+
const msg = ref('Hello World!')
116+
const show = ref(true)
117+
118+
// @ts-expect-error
119+
return (_ctx, _cache) => {
120+
return (
121+
_openBlock(),
122+
_createElementBlock('div', null, [
123+
_createElementVNode(
124+
'h1',
125+
null,
126+
_toDisplayString(msg.value),
127+
1 /* TEXT */,
128+
),
129+
show.value
130+
? _withDirectives(
131+
(_openBlock(),
132+
_createElementBlock(
133+
'input',
134+
{
135+
key: 0,
136+
'onUpdate:modelValue':
137+
_cache[0] ||
138+
(_cache[0] = ($event: any) => (msg.value = $event)),
139+
},
140+
null,
141+
512 /* NEED_PATCH */,
142+
)),
143+
[[_vModelText, msg.value]],
144+
)
145+
: _createCommentVNode('v-if', true),
146+
_createElementVNode('div', null, [
147+
(_openBlock(),
148+
_createElementBlock(
149+
_Fragment,
150+
null,
151+
_renderList(5, item => {
152+
return _createElementVNode(
153+
'div',
154+
null,
155+
_toDisplayString(item),
156+
1 /* TEXT */,
157+
)
158+
}),
159+
64 /* STABLE_FRAGMENT */,
160+
)),
161+
]),
162+
_cache[1] ||
163+
(_cache[1] = _createElementVNode(
164+
'span',
165+
null,
166+
null,
167+
-1 /* CACHED */,
168+
)),
169+
])
170+
)
171+
}
172+
},
173+
}
174+
175+
const VdomApp = {
176+
setup() {
177+
const msg = ref('hi')
178+
return () => {
179+
return (
180+
_openBlock(),
181+
_createElementBlock('div', null, [
182+
_createVNode(VdomChild, null, {
183+
default: _withCtx(() => [
184+
_createElementVNode(
185+
'span',
186+
null,
187+
_toDisplayString(msg.value),
188+
1 /* TEXT */,
189+
),
190+
]),
191+
_: 1 /* STABLE */,
192+
}),
193+
])
194+
)
195+
}
196+
},
197+
}
198+
199+
bench('vapor', () => {
200+
try {
201+
__DEV__ = false
202+
const container = document.createElement('div')
203+
container.innerHTML = html
204+
205+
const app = createVaporSSRApp(VaporApp)
206+
app.mount(container)
207+
} finally {
208+
__DEV__ = true
209+
}
210+
})
211+
212+
bench('vdom', () => {
213+
try {
214+
__DEV__ = false
215+
const container = document.createElement('div')
216+
container.innerHTML = html
217+
218+
const app = createSSRApp(VdomApp)
219+
app.mount(container)
220+
} finally {
221+
__DEV__ = true
222+
}
223+
})
224+
}
225+
})

0 commit comments

Comments
 (0)