Skip to content

Commit b0d2257

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

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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+
createElementBlock as _createElementBlock,
13+
createElementVNode as _createElementVNode,
14+
createVNode as _createVNode,
15+
openBlock as _openBlock,
16+
renderList as _renderList,
17+
toDisplayString as _toDisplayString,
18+
vModelText as _vModelText,
19+
withDirectives as _withDirectives,
20+
createSSRApp,
21+
ref,
22+
} from '@vue/runtime-dom'
23+
import {
24+
applyTextModel as _applyTextModel,
25+
child as _child,
26+
createComponent as _createComponent,
27+
createFor as _createFor,
28+
renderEffect as _renderEffect,
29+
setInsertionState as _setInsertionState,
30+
setText as _setText,
31+
template as _template,
32+
createVaporSSRApp,
33+
} from '@vue/runtime-vapor'
34+
35+
describe('hydration benchmark', () => {
36+
let html = `<div><!--[--><h1>Hello World!</h1><input value="Hello World!"><!--]--></div>`
37+
38+
const t0 = _template('<h1> </h1>')
39+
const t1 = _template('<input>')
40+
41+
const VaporChild = {
42+
__vapor: true,
43+
setup() {
44+
const msg = ref('Hello World!')
45+
46+
const n0 = t0() as any
47+
const n1 = t1() as any
48+
const x0 = _child(n0) as any
49+
_applyTextModel(
50+
n1,
51+
() => msg.value,
52+
_value => (msg.value = _value),
53+
)
54+
_renderEffect(() => _setText(x0, _toDisplayString(msg.value)))
55+
return [n0, n1]
56+
},
57+
}
58+
const _t0 = _template('<div></div>', true)
59+
const VaporApp = {
60+
__vapor: true,
61+
setup() {
62+
const n1 = _t0() as any
63+
_setInsertionState(n1)
64+
_createComponent(VaporChild)
65+
return n1
66+
},
67+
}
68+
69+
const VdomChild = {
70+
setup() {
71+
const msg = ref('foo')
72+
73+
// @ts-expect-error
74+
return (_ctx, _cache) => {
75+
return (
76+
_openBlock(),
77+
_createElementBlock(
78+
_Fragment,
79+
null,
80+
[
81+
_createElementVNode(
82+
'h1',
83+
null,
84+
_toDisplayString(msg.value),
85+
1 /* TEXT */,
86+
),
87+
_withDirectives(
88+
_createElementVNode(
89+
'input',
90+
{
91+
'onUpdate:modelValue':
92+
_cache[0] ||
93+
(_cache[0] = ($event: any) => (msg.value = $event)),
94+
},
95+
null,
96+
512 /* NEED_PATCH */,
97+
),
98+
[[_vModelText, msg.value]],
99+
),
100+
],
101+
64 /* STABLE_FRAGMENT */,
102+
)
103+
)
104+
}
105+
},
106+
}
107+
108+
const VdomApp = {
109+
setup() {
110+
return () => {
111+
return (
112+
_openBlock(),
113+
_createElementBlock('div', null, [_createVNode(VdomChild)])
114+
)
115+
}
116+
},
117+
}
118+
119+
bench('vapor', () => {
120+
try {
121+
__DEV__ = false
122+
const container = document.createElement('div')
123+
container.innerHTML = html
124+
125+
const app = createVaporSSRApp(VaporApp)
126+
app.mount(container)
127+
} finally {
128+
__DEV__ = true
129+
}
130+
})
131+
132+
bench('vdom', () => {
133+
try {
134+
__DEV__ = false
135+
const container = document.createElement('div')
136+
container.innerHTML = html
137+
138+
const app = createSSRApp(VdomApp)
139+
app.mount(container)
140+
} finally {
141+
__DEV__ = true
142+
}
143+
})
144+
})

0 commit comments

Comments
 (0)