Skip to content

Commit

Permalink
workflow: bench against bundled dist file to avoid import access over…
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Nov 14, 2024
1 parent 3656364 commit e9f3e6b
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 8 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"test-dts": "run-s build-dts test-dts-only",
"test-dts-only": "tsc -p packages-private/dts-built-test/tsconfig.json && tsc -p ./packages-private/dts-test/tsconfig.test.json",
"test-coverage": "vitest run --project unit --coverage",
"prebench": "node scripts/build.js -pf esm-browser reactivity",
"prebench-compare": "node scripts/build.js -pf esm-browser reactivity",
"bench": "vitest bench --project=unit --outputJson=temp/bench.json",
"bench-compare": "vitest bench --project=unit --compare=temp/bench.json",
"release": "node scripts/release.js",
Expand Down
7 changes: 6 additions & 1 deletion packages/reactivity/__benchmarks__/computed.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import { bench, describe } from 'vitest'
import { type ComputedRef, type Ref, computed, effect, ref } from '../src'
import type { ComputedRef, Ref } from '../src'
import { computed, effect, ref } from '../dist/reactivity.esm-browser.prod'

declare module '../dist/reactivity.esm-browser.prod' {
function computed(...args: any[]): any
}

describe('computed', () => {
bench('create computed', () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/reactivity/__benchmarks__/effect.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { bench, describe } from 'vitest'
import { type Ref, effect, ref } from '../src'
import type { Ref } from '../src'
import { effect, ref } from '../dist/reactivity.esm-browser.prod'

describe('effect', () => {
{
Expand Down
6 changes: 5 additions & 1 deletion packages/reactivity/__benchmarks__/reactiveArray.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { bench } from 'vitest'
import { effect, reactive, shallowReadArray } from '../src'
import {
effect,
reactive,
shallowReadArray,
} from '../dist/reactivity.esm-browser.prod'

for (let amount = 1e1; amount < 1e4; amount *= 10) {
{
Expand Down
3 changes: 2 additions & 1 deletion packages/reactivity/__benchmarks__/reactiveMap.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { bench } from 'vitest'
import { type ComputedRef, computed, reactive } from '../src'
import type { ComputedRef } from '../src'
import { computed, reactive } from '../dist/reactivity.esm-browser.prod'

function createMap(obj: Record<string, any>) {
const map = new Map()
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/__benchmarks__/reactiveObject.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bench } from 'vitest'
import { reactive } from '../src'
import { reactive } from '../dist/reactivity.esm-browser.prod'

bench('create reactive obj', () => {
reactive({ a: 1 })
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/__benchmarks__/ref.bench.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bench, describe } from 'vitest'
import { ref } from '../src/index'
import { ref } from '../dist/reactivity.esm-browser.prod'

describe('ref', () => {
bench('create ref', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/server-renderer/__tests__/createBuffer.bench.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { bench, describe } from 'vitest'

import { createBuffer } from '../src/render'
import { createBuffer as _createBuffer } from '../src/render'

// move to local const to avoid import access overhead
// https://github.com/vitest-dev/vitest/issues/6903
const createBuffer = _createBuffer

describe('createBuffer', () => {
let stringBuffer = createBuffer()
Expand Down
6 changes: 5 additions & 1 deletion packages/server-renderer/__tests__/unrollBuffer.bench.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { bench, describe } from 'vitest'

import { type SSRBuffer, createBuffer } from '../src/render'
import { unrollBuffer } from '../src/renderToString'
import { unrollBuffer as _unrollBuffer } from '../src/renderToString'

// move to local const to avoid import access overhead
// https://github.com/vitest-dev/vitest/issues/6903
const unrollBuffer = _unrollBuffer

function createSyncBuffer(levels: number, itemsPerLevel: number): SSRBuffer {
const buffer = createBuffer()
Expand Down

0 comments on commit e9f3e6b

Please sign in to comment.