Vue.js ({{ isVapor ? 'Vapor' : 'Virtual DOM' }}) Benchmark
+
+
+
+
+
+
}
globalThis.recordTime = true
globalThis.doProfile = false
+globalThis.reactivity = false
export const defer = () => new Promise(r => requestIdleCallback(r))
@@ -34,7 +36,18 @@ export function wrap(
fn(...args)
await defer()
- const time = performance.now() - start
+ let time: number
+ if (globalThis.reactivity) {
+ time = performance.measure(
+ 'flushJobs-measure',
+ 'flushJobs-start',
+ 'flushJobs-end',
+ ).duration
+ performance.clearMarks()
+ performance.clearMeasures()
+ } else {
+ time = performance.now() - start
+ }
const prevTimes = times[id] || (times[id] = [])
prevTimes.push(time)
diff --git a/benchmark/index.js b/benchmark/index.js
index 7ea24ec1f..2332761ec 100644
--- a/benchmark/index.js
+++ b/benchmark/index.js
@@ -88,9 +88,11 @@ if (!skipBench) {
async function buildLib() {
console.info(colors.blue('Building lib...'))
+ /** @type {import('node:child_process').SpawnOptions} */
const options = {
cwd: path.resolve(import.meta.dirname, '..'),
stdio: 'inherit',
+ env: { ...process.env, BENCHMARK: 'true' },
}
const buildOptions = devBuild ? '-df' : '-pf'
const [{ ok }, { ok: ok2 }, { ok: ok3 }, { ok: ok4 }] = await Promise.all([
@@ -130,7 +132,7 @@ async function buildApp(isVapor) {
colors.blue(`\nBuilding ${isVapor ? 'Vapor' : 'Virtual DOM'} app...\n`),
)
- process.env.NODE_ENV = 'production'
+ if (!devBuild) process.env.NODE_ENV = 'production'
const CompilerSFC = await import(
'../packages/compiler-sfc/dist/compiler-sfc.cjs.js'
)
diff --git a/packages/global.d.ts b/packages/global.d.ts
index 8b627d2e5..e6acf0d1b 100644
--- a/packages/global.d.ts
+++ b/packages/global.d.ts
@@ -9,6 +9,7 @@ declare var __CJS__: boolean
declare var __SSR__: boolean
declare var __VERSION__: string
declare var __COMPAT__: boolean
+declare var __BENCHMARK__: boolean
// Feature flags
declare var __FEATURE_OPTIONS_API__: boolean
diff --git a/packages/runtime-vapor/src/scheduler.ts b/packages/runtime-vapor/src/scheduler.ts
index 5b3a1e93a..cfdfd1349 100644
--- a/packages/runtime-vapor/src/scheduler.ts
+++ b/packages/runtime-vapor/src/scheduler.ts
@@ -139,6 +139,7 @@ export function flushPostFlushCbs(): void {
// TODO: dev mode and checkRecursiveUpdates
function flushJobs() {
+ if (__BENCHMARK__) performance.mark('flushJobs-start')
isFlushPending = false
isFlushing = true
@@ -169,6 +170,7 @@ function flushJobs() {
if (queue.length || pendingPostFlushCbs.length) {
flushJobs()
}
+ if (__BENCHMARK__) performance.mark('flushJobs-end')
}
}
diff --git a/playground/setup/dev.js b/playground/setup/dev.js
index a6ba15274..8f24be757 100644
--- a/playground/setup/dev.js
+++ b/playground/setup/dev.js
@@ -51,6 +51,7 @@ export function DevPlugin({ browser = false } = {}) {
__NODE_JS__: String(false),
// need SSR-specific branches?
__SSR__: String(false),
+ __BENCHMARK__: 'false',
// 2.x compat build
__COMPAT__: String(false),
diff --git a/rollup.config.js b/rollup.config.js
index 0efe1326a..2ed8bb09f 100644
--- a/rollup.config.js
+++ b/rollup.config.js
@@ -218,6 +218,7 @@ function createConfig(format, output, plugins = []) {
__CJS__: String(isCJSBuild),
// need SSR-specific branches?
__SSR__: String(!isGlobalBuild),
+ __BENCHMARK__: process.env.BENCHMARK || 'false',
// 2.x compat build
__COMPAT__: String(isCompatBuild),
diff --git a/scripts/dev.js b/scripts/dev.js
index fb4d3873e..a43d1142a 100644
--- a/scripts/dev.js
+++ b/scripts/dev.js
@@ -151,6 +151,7 @@ for (const target of targets) {
__ESM_BROWSER__: String(format.includes('esm-browser')),
__CJS__: String(format === 'cjs'),
__SSR__: String(format !== 'global'),
+ __BENCHMARK__: process.env.BENCHMARK || 'false',
__COMPAT__: String(target === 'vue-compat'),
__FEATURE_SUSPENSE__: `true`,
__FEATURE_OPTIONS_API__: `true`,
diff --git a/vitest.config.ts b/vitest.config.ts
index fb67562fc..4d7285f76 100644
--- a/vitest.config.ts
+++ b/vitest.config.ts
@@ -12,6 +12,7 @@ export default defineConfig({
__ESM_BROWSER__: false,
__CJS__: true,
__SSR__: true,
+ __BENCHMARK__: false,
__FEATURE_OPTIONS_API__: true,
__FEATURE_SUSPENSE__: true,
__FEATURE_PROD_DEVTOOLS__: false,