Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,3 @@ jobs:
env:
CODSPEED_SKIP_UPLOAD: true
CODSPEED_DEBUG: true

walltime-macos-test:
runs-on: macos-latest
steps:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
cache: pnpm
node-version-file: .nvmrc
- name: Restore turbo cache
uses: ./.github/actions/turbo-cache
- run: pnpm install --frozen-lockfile --prefer-offline
- run: pnpm turbo run build

- name: Run benchmarks
uses: CodSpeedHQ/action@main
env:
CODSPEED_SKIP_UPLOAD: "true"
# Samply fails to profile pnpm targets for now
CODSPEED_PROFILER_ENABLED: "false"
with:
run: pnpm turbo run bench --filter=@codspeed/vitest-plugin
mode: walltime
25 changes: 25 additions & 0 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ jobs:
pnpm --workspace-concurrency 1 -r bench-tinybench
pnpm --workspace-concurrency 1 -r bench-vitest

codspeed-walltime-macos:
runs-on: macos-latest
steps:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
with:
cache: pnpm
node-version-file: .nvmrc
- name: Restore turbo cache
uses: ./.github/actions/turbo-cache
- run: pnpm install --frozen-lockfile --prefer-offline
- run: pnpm turbo run build

- name: Run macOS-only benchmarks
uses: CodSpeedHQ/action@main
with:
working-directory: packages/vitest-plugin
run: pnpm turbo run bench --filter=@codspeed/vitest-plugin
mode: walltime
runner-version: branch:sip-resign-exec-redirect

electron-e2e:
name: Run electron inbox e2e
runs-on: codspeed-macro
Expand Down
17 changes: 17 additions & 0 deletions packages/tinybench-plugin/src/walltime.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import {
calculateQuantiles,
InstrumentHooks,
MARKER_TYPE_BENCHMARK_END,
MARKER_TYPE_BENCHMARK_START,
mongoMeasurement,
msToNs,
msToS,
Expand Down Expand Up @@ -64,17 +67,31 @@ class WalltimeBenchRunner extends BaseBenchRunner {

private wrapTaskFunction(task: Task, isAsync: boolean): void {
const { fn } = task as unknown as { fn: Fn };
const pid = process.pid;

// Emit per-round markers so the walltime instrument can bracket the actual
// benchmark body (excluding the harness) when attributing perf samples.
const finishRound = (roundStart: bigint): void => {
const roundEnd = InstrumentHooks.currentTimestamp();
InstrumentHooks.addMarker(pid, MARKER_TYPE_BENCHMARK_START, roundStart);
InstrumentHooks.addMarker(pid, MARKER_TYPE_BENCHMARK_END, roundEnd);
};

if (isAsync) {
// eslint-disable-next-line no-inner-declarations
async function __codspeed_root_frame__() {
const roundStart = InstrumentHooks.currentTimestamp();
await fn();
finishRound(roundStart);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(task as any).fn = __codspeed_root_frame__;
} else {
// eslint-disable-next-line no-inner-declarations
function __codspeed_root_frame__() {
const roundStart = InstrumentHooks.currentTimestamp();
fn();
finishRound(roundStart);
}
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(task as any).fn = __codspeed_root_frame__;
Expand Down
16 changes: 16 additions & 0 deletions packages/vitest-plugin/benches/macos.bench.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { bench, describe } from "vitest";

const isMacOS = process.platform === "darwin";

function fibo(n: number): number {
if (n < 2) return 1;
return fibo(n - 1) + fibo(n - 2);
}

// macOS-only benchmark: skipped on every other platform, so it only runs on
// the `walltime-macos-test` CI job (see .github/workflows/ci.yml).
describe.skipIf(!isMacOS)("macos only", () => {
bench("fibo darwin", () => {
fibo(30);
});
});
30 changes: 26 additions & 4 deletions packages/vitest-plugin/src/walltime/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {
InstrumentHooks,
MARKER_TYPE_BENCHMARK_END,
MARKER_TYPE_BENCHMARK_START,
setupCore,
writeWalltimeResults,
} from "@codspeed/core";
Expand Down Expand Up @@ -66,6 +68,7 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
this.isTinybenchHookedWithCodspeed = true;

const originalRun = tinybench.Task.prototype.run;
const pid = process.pid;

const getSuiteUri = (): string => {
if (this.currentSuiteId === null) {
Expand All @@ -78,18 +81,37 @@ export class WalltimeRunner extends NodeBenchmarkRunner {
const { fn } = this as { fn: Fn };
const suiteUri = getSuiteUri();

function __codspeed_root_frame__() {
return fn();
const finishRound = (roundStart: bigint): void => {
const roundEnd = InstrumentHooks.currentTimestamp();
InstrumentHooks.addMarker(pid, MARKER_TYPE_BENCHMARK_START, roundStart);
InstrumentHooks.addMarker(pid, MARKER_TYPE_BENCHMARK_END, roundEnd);
};

function __codspeed_root_frame__(): unknown {
const roundStart = InstrumentHooks.currentTimestamp();
const result = fn();
if (
result !== null &&
typeof result === "object" &&
typeof (result as PromiseLike<unknown>).then === "function"
) {
return (result as PromiseLike<unknown>).then((value) => {
finishRound(roundStart);
return value;
});
}
finishRound(roundStart);
return result;
}
(this as { fn: Fn }).fn = __codspeed_root_frame__;
(this as { fn: Fn }).fn = __codspeed_root_frame__ as Fn;

InstrumentHooks.startBenchmark();
await originalRun.call(this);
InstrumentHooks.stopBenchmark();

// Look up the URI by task name
const uri = `${suiteUri}::${this.name}`;
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
InstrumentHooks.setExecutedBenchmark(pid, uri);

return this;
};
Expand Down
Loading