diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b26f64db..720726b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -64,6 +64,7 @@ jobs: # use version from `main` branch to always test the latest version, in real projects, use a tag, like `@v2` uses: CodSpeedHQ/action@main with: + mode: instrumentation run: pnpm --filter ${{ matrix.example }} bench-tinybench env: CODSPEED_SKIP_UPLOAD: true @@ -72,6 +73,7 @@ jobs: # use version from `main` branch to always test the latest version, in real projects, use a tag, like `@v2` uses: CodSpeedHQ/action@main with: + mode: instrumentation run: pnpm --filter ${{ matrix.example }} bench-benchmark-js env: CODSPEED_SKIP_UPLOAD: true diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index 1695e38b..9c002e5f 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -27,8 +27,11 @@ jobs: # use version from `main` branch to always test the latest version, in real projects, use a tag, like `@v2` uses: CodSpeedHQ/action@main with: + mode: instrumentation run: | - pnpm moon run --concurrency 1 :bench + pnpm moon run tinybench-plugin:bench + pnpm moon run vitest-plugin:bench + pnpm moon run benchmark.js-plugin:bench pnpm --workspace-concurrency 1 -r bench-tinybench pnpm --workspace-concurrency 1 -r bench-benchmark-js pnpm --workspace-concurrency 1 -r bench-vitest @@ -53,8 +56,10 @@ jobs: # use version from `main` branch to always test the latest version, in real projects, use a tag, like `@v2` uses: CodSpeedHQ/action@main with: - # Only tinybench supports walltime for now + mode: walltime run: | - pnpm moon run --concurrency 1 :bench + pnpm moon run tinybench-plugin:bench + pnpm moon run vitest-plugin:bench + pnpm moon run benchmark.js-plugin:bench pnpm --workspace-concurrency 1 -r bench-tinybench pnpm --workspace-concurrency 1 -r bench-vitest diff --git a/lerna.json b/lerna.json index d9d77fcd..9819cb20 100644 --- a/lerna.json +++ b/lerna.json @@ -1,7 +1,9 @@ { "npmClient": "pnpm", "useWorkspaces": true, - "packages": ["packages/*"], + "packages": [ + "packages/*" + ], "$schema": "node_modules/lerna/schemas/lerna-schema.json", - "version": "4.0.1" + "version": "5.0.0" } diff --git a/packages/benchmark.js-plugin/package.json b/packages/benchmark.js-plugin/package.json index a99ed43c..9b7ca25b 100644 --- a/packages/benchmark.js-plugin/package.json +++ b/packages/benchmark.js-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@codspeed/benchmark.js-plugin", - "version": "4.0.1", + "version": "5.0.0", "description": "Benchmark.js compatibility layer for CodSpeed", "keywords": [ "codspeed", @@ -27,7 +27,7 @@ "jest-mock-extended": "^3.0.4" }, "dependencies": { - "@codspeed/core": "workspace:^4.0.1", + "@codspeed/core": "workspace:^5.0.0", "lodash": "^4.17.10", "stack-trace": "1.0.0-pre2" }, diff --git a/packages/core/package.json b/packages/core/package.json index ad5dba6a..1fc2345f 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "@codspeed/core", - "version": "4.0.1", + "version": "5.0.0", "description": "The core Node library used to integrate with Codspeed runners", "keywords": [ "codspeed", diff --git a/packages/core/src/introspection.ts b/packages/core/src/introspection.ts index 1be58ab1..ce965922 100644 --- a/packages/core/src/introspection.ts +++ b/packages/core/src/introspection.ts @@ -1,28 +1,35 @@ import { writeFileSync } from "fs"; +import { getCodspeedRunnerMode } from "."; const CUSTOM_INTROSPECTION_EXIT_CODE = 0; export const getV8Flags = () => { const nodeVersionMajor = parseInt(process.version.slice(1).split(".")[0]); + const codspeedRunnerMode = getCodspeedRunnerMode(); - const flags = [ - "--hash-seed=1", - "--random-seed=1", - "--no-opt", - "--predictable", - "--predictable-gc-schedule", - "--interpreted-frames-native-stack", - "--allow-natives-syntax", - "--expose-gc", - "--no-concurrent-sweeping", - "--max-old-space-size=4096", - ]; - if (nodeVersionMajor < 18) { - flags.push("--no-randomize-hashes"); - } - if (nodeVersionMajor < 20) { - flags.push("--no-scavenge-task"); + const flags = ["--interpreted-frames-native-stack", "--allow-natives-syntax"]; + + if (codspeedRunnerMode === "instrumented") { + flags.push( + ...[ + "--hash-seed=1", + "--random-seed=1", + "--no-opt", + "--predictable", + "--predictable-gc-schedule", + "--expose-gc", + "--no-concurrent-sweeping", + "--max-old-space-size=4096", + ] + ); + if (nodeVersionMajor < 18) { + flags.push("--no-randomize-hashes"); + } + if (nodeVersionMajor < 20) { + flags.push("--no-scavenge-task"); + } } + return flags; }; diff --git a/packages/tinybench-plugin/package.json b/packages/tinybench-plugin/package.json index db43c514..f5c41f57 100644 --- a/packages/tinybench-plugin/package.json +++ b/packages/tinybench-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@codspeed/tinybench-plugin", - "version": "4.0.1", + "version": "5.0.0", "description": "tinybench compatibility layer for CodSpeed", "keywords": [ "codspeed", @@ -31,7 +31,7 @@ "vitest": "^3.2.4" }, "dependencies": { - "@codspeed/core": "workspace:^4.0.1", + "@codspeed/core": "workspace:^5.0.0", "stack-trace": "1.0.0-pre2" }, "peerDependencies": { diff --git a/packages/tinybench-plugin/src/walltime.ts b/packages/tinybench-plugin/src/walltime.ts index 2c22c539..28933b5b 100644 --- a/packages/tinybench-plugin/src/walltime.ts +++ b/packages/tinybench-plugin/src/walltime.ts @@ -7,7 +7,7 @@ import { type Benchmark, type BenchmarkStats, } from "@codspeed/core"; -import { Bench, TaskResult } from "tinybench"; +import { Bench, Fn, TaskResult } from "tinybench"; import { getTaskUri } from "./uri"; declare const __VERSION__: string; @@ -35,6 +35,14 @@ export function runWalltimeBench(bench: Bench, rootCallingFile: string): void { for (const task of bench.tasks) { const uri = getTaskUri(bench, task.name, rootCallingFile); + const { fn } = task as unknown as { fn: Fn }; + // eslint-disable-next-line no-inner-declarations + async function __codspeed_root_frame__() { + await fn(); + } + // eslint-disable-next-line @typescript-eslint/no-explicit-any + (task as any).fn = __codspeed_root_frame__; + // run the warmup of the task right before its actual run if (bench.opts.warmup) { await task.warmup(); diff --git a/packages/vitest-plugin/package.json b/packages/vitest-plugin/package.json index f26c53e7..3a4c336c 100644 --- a/packages/vitest-plugin/package.json +++ b/packages/vitest-plugin/package.json @@ -1,6 +1,6 @@ { "name": "@codspeed/vitest-plugin", - "version": "4.0.1", + "version": "5.0.0", "description": "vitest plugin for CodSpeed", "keywords": [ "codspeed", @@ -28,7 +28,7 @@ "bench": "vitest bench" }, "dependencies": { - "@codspeed/core": "workspace:^4.0.1" + "@codspeed/core": "workspace:^5.0.0" }, "peerDependencies": { "vite": "^4.2.0 || ^5.0.0 || ^6.0.0 || ^7.0.0", diff --git a/packages/vitest-plugin/src/__tests__/index.test.ts b/packages/vitest-plugin/src/__tests__/index.test.ts index 290b0dde..b0322819 100644 --- a/packages/vitest-plugin/src/__tests__/index.test.ts +++ b/packages/vitest-plugin/src/__tests__/index.test.ts @@ -93,13 +93,13 @@ describe("codSpeedPlugin", () => { poolOptions: { forks: { execArgv: [ + "--interpreted-frames-native-stack", + "--allow-natives-syntax", "--hash-seed=1", "--random-seed=1", "--no-opt", "--predictable", "--predictable-gc-schedule", - "--interpreted-frames-native-stack", - "--allow-natives-syntax", "--expose-gc", "--no-concurrent-sweeping", "--max-old-space-size=4096", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5b8bb92e..98e6f532 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -213,7 +213,7 @@ importers: packages/benchmark.js-plugin: dependencies: '@codspeed/core': - specifier: workspace:^4.0.1 + specifier: workspace:^5.0.0 version: link:../core lodash: specifier: ^4.17.10 @@ -275,7 +275,7 @@ importers: packages/tinybench-plugin: dependencies: '@codspeed/core': - specifier: workspace:^4.0.1 + specifier: workspace:^5.0.0 version: link:../core stack-trace: specifier: 1.0.0-pre2 @@ -297,7 +297,7 @@ importers: packages/vitest-plugin: dependencies: '@codspeed/core': - specifier: workspace:^4.0.1 + specifier: workspace:^5.0.0 version: link:../core devDependencies: '@total-typescript/shoehorn':