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
2 changes: 1 addition & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"ignorePatterns": [
"**/dist/**",
"**/node_modules/**",
"**/rollup.config.ts",
"**/rollup.config.mjs",
"**/jest.config.js",
"packages/core/src/native_core/instruments/hooks/**"
],
Expand Down
20 changes: 7 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
cache: pnpm
node-version-file: .nvmrc
Expand Down Expand Up @@ -49,22 +49,16 @@ jobs:
needs: list-examples
strategy:
matrix:
node-version: ["18", "20.5.1"]
node-version: ["22", "24"]
example: ${{ fromJson(needs.list-examples.outputs.examples) }}
# tinybench v5+ requires Node >=20, so its examples cannot run on Node 18
exclude:
- node-version: "18"
example: "with-tinybench-v5"
- node-version: "18"
example: "with-tinybench-v6"
fail-fast: false
steps:
- uses: "actions/checkout@v4"
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
cache: pnpm
node-version: ${{ matrix.node-version }}
Expand All @@ -79,7 +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
mode: simulation
run: pnpm --filter ${{ matrix.example }} bench-tinybench
env:
CODSPEED_SKIP_UPLOAD: true
Expand All @@ -88,7 +82,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
mode: simulation
run: pnpm --filter ${{ matrix.example }} bench-benchmark-js
env:
CODSPEED_SKIP_UPLOAD: true
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/codspeed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
cache: pnpm
node-version-file: .nvmrc
Expand Down Expand Up @@ -69,8 +69,8 @@ jobs:
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
cache: pnpm
node-version-file: .nvmrc
Expand Down Expand Up @@ -100,8 +100,8 @@ jobs:
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
cache: pnpm
node-version-file: .nvmrc
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ jobs:
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
cache: pnpm
node-version-file: .nvmrc
Expand All @@ -51,8 +51,8 @@ jobs:
with:
fetch-depth: 0
submodules: true
- uses: pnpm/action-setup@v2
- uses: actions/setup-node@v3
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v6
with:
cache: pnpm
node-version-file: .nvmrc
Expand All @@ -78,7 +78,8 @@ jobs:
fi
env:
NPM_CONFIG_PROVENANCE: true
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Surfaces npm's OIDC token exchange, which is otherwise silent.
NPM_CONFIG_LOGLEVEL: verbose

- if: github.event_name == 'push'
name: Create a draft release
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20.5.1
24.19.0
4 changes: 2 additions & 2 deletions examples/with-tinybench-v5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"private": true,
"type": "module",
"scripts": {
"bench-tinybench": "node --loader esbuild-register/loader -r esbuild-register tinybench.ts",
"bench-tinybench": "node --import tsx tinybench.ts",
"typecheck": "tsc --noEmit --pretty"
},
"devDependencies": {
"@codspeed/tinybench-plugin": "workspace:*",
"esbuild-register": "^3.4.2",
"tinybench": "^5.1.0",
"tsx": "^4.23.12",
"typescript": "^5.1.3"
}
}
4 changes: 2 additions & 2 deletions examples/with-tinybench-v6/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"private": true,
"type": "module",
"scripts": {
"bench-tinybench": "node --loader esbuild-register/loader -r esbuild-register tinybench.ts",
"bench-tinybench": "node --import tsx tinybench.ts",
"typecheck": "tsc --noEmit --pretty"
},
"devDependencies": {
"@codspeed/tinybench-plugin": "workspace:*",
"esbuild-register": "^3.4.2",
"tinybench": "^6.0.2",
"tsx": "^4.23.12",
"typescript": "^5.1.3"
}
}
6 changes: 3 additions & 3 deletions examples/with-typescript-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"private": true,
"type": "module",
"scripts": {
"bench-benchmark-js": "node --loader esbuild-register/loader -r esbuild-register bench/benchmark.js/index.bench.ts",
"bench-tinybench": "node --loader esbuild-register/loader -r esbuild-register bench/tinybench/index.bench.ts",
"bench-benchmark-js": "node --import tsx bench/benchmark.js/index.bench.ts",
"bench-tinybench": "node --import tsx bench/tinybench/index.bench.ts",
"bench-vitest": "vitest bench --run"
},
"devDependencies": {
Expand All @@ -13,8 +13,8 @@
"@codspeed/vitest-plugin": "workspace:*",
"@types/benchmark": "^2.1.2",
"benchmark": "^2.1.4",
"esbuild-register": "^3.4.2",
"tinybench": "^4.0.1",
"tsx": "^4.23.12",
"typescript": "^5.1.3",
"vitest": "^4.0.18"
}
Expand Down
6 changes: 3 additions & 3 deletions examples/with-typescript-simple-esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
"private": true,
"type": "module",
"scripts": {
"bench-benchmark-js": "node --loader esbuild-register/loader -r esbuild-register benchmark-js.ts",
"bench-tinybench": "node --loader esbuild-register/loader -r esbuild-register tinybench.ts"
"bench-benchmark-js": "node --import tsx benchmark-js.ts",
"bench-tinybench": "node --import tsx tinybench.ts"
},
"devDependencies": {
"@codspeed/benchmark.js-plugin": "workspace:*",
"@codspeed/tinybench-plugin": "workspace:*",
"@types/benchmark": "^2.1.2",
"benchmark": "^2.1.4",
"esbuild-register": "^3.4.2",
"tinybench": "^4.0.1",
"tsx": "^4.23.12",
"typescript": "^5.1.3"
}
}
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-typescript": "^11.1.5",
"@types/jest": "^29.5.0",
"@types/node": "^20.5.1",
"@types/node": "^24.10.1",
"@typescript-eslint/eslint-plugin": "^8.57.0",
"@typescript-eslint/parser": "^8.57.0",
"esbuild": "^0.17.16",
Expand All @@ -42,7 +42,12 @@
"typescript": "^5.6.3"
},
"packageManager": "pnpm@10.12.4",
"pnpm": {
"overrides": {
"node-abi": "3.95.0"
}
},
"engines": {
"node": "20.5.1"
"node": ">=22"
}
}
2 changes: 1 addition & 1 deletion packages/benchmark.js-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dist"
],
"scripts": {
"build": "NODE_NO_WARNINGS=1 rollup -c rollup.config.ts --configPlugin typescript",
"build": "rollup -c",
"test": "jest --passWithNoTests --silent",
"test/integ": "jest --passWithNoTests --silent -c jest.config.integ.js",
"lint": "eslint .",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from "rollup";
import { declarationsPlugin, jsPlugins } from "../../rollup.options";
import { declarationsPlugin, jsPlugins } from "../../rollup.options.mjs";
import pkg from "./package.json" with { type: "json" };

const entrypoint = "src/index.ts";
Expand Down
6 changes: 3 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"types": "dist/index.d.ts",
"gypfile": true,
"scripts": {
"build": "NODE_NO_WARNINGS=1 rollup -c rollup.config.ts --configPlugin typescript",
"build-native-addon": "prebuildify --napi --strip",
"build": "rollup -c",
"build-native-addon": "prebuildify --name node --strip --no-napi --target 22.0.0 --target 24.0.0",
"build-tracer-client": "openapi --client axios --input ./tracer.spec.json --name MongoTracer --output ./src/generated/openapi",
"test": "jest --passWithNoTests --silent",
"test/integ": "jest --passWithNoTests --silent -c jest.config.integ.js",
Expand All @@ -37,7 +37,7 @@
"node-addon-api": "^5.1.0",
"node-gyp": "^12.2.0",
"openapi-typescript-codegen": "^0.23.0",
"prebuildify": "^5.0.1"
"prebuildify": "^6.0.1"
},
"dependencies": {
"axios": "^1.4.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from "rollup";
import { declarationsPlugin, jsPlugins } from "../../rollup.options";
import { declarationsPlugin, jsPlugins } from "../../rollup.options.mjs";
import pkg from "./package.json" with { type: "json" };

const entrypoint = "src/index.ts";
Expand Down Expand Up @@ -27,5 +27,13 @@ export default defineConfig([
{ file: pkg.module, format: "es", sourcemap: true },
],
plugins: jsPlugins(pkg.version),
onwarn(warning, warn) {
// The optimization helpers reach V8 natives syntax
// (%OptimizeFunctionOnNextCall), which has no non-eval entry point.
if (warning.code === "EVAL" && warning.id?.endsWith("optimization.ts")) {
return;
}
warn(warning);
},
},
]);
42 changes: 3 additions & 39 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { checkV8Flags } from "./introspection";
import { MongoMeasurement } from "./mongoMeasurement";
import native_core from "./native_core";
import { getCodspeedRunnerMode } from "./runnerMode";

declare const __VERSION__: string;

Expand All @@ -10,44 +11,6 @@ export const isBound = native_core.isBound;

export const mongoMeasurement = new MongoMeasurement();

type CodSpeedRunnerMode = "disabled" | "simulation" | "memory" | "walltime";

type InstrumentMode = "disabled" | "analysis" | "walltime";

export function getCodspeedRunnerMode(): CodSpeedRunnerMode {
const isCodSpeedEnabled = process.env.CODSPEED_ENV !== undefined;
if (!isCodSpeedEnabled) {
return "disabled";
}

// If CODSPEED_ENV is set, check CODSPEED_RUNNER_MODE
const codspeedRunnerMode = process.env.CODSPEED_RUNNER_MODE;
if (
codspeedRunnerMode === "instrumentation" ||
codspeedRunnerMode === "simulation"
) {
return "simulation";
} else if (codspeedRunnerMode === "memory") {
return "memory";
} else if (codspeedRunnerMode === "walltime") {
return "walltime";
}

console.warn(
`Unknown codspeed runner mode: ${codspeedRunnerMode}, defaulting to disabled`,
);
return "disabled";
}

export function getInstrumentMode(): InstrumentMode {
const runnerMode = getCodspeedRunnerMode();
// Both "simulation" and "memory" map to "analysis" instrument mode
if (runnerMode === "simulation" || runnerMode === "memory") {
return "analysis";
}
return runnerMode; // "disabled" or "walltime"
}

export const setupCore = () => {
if (!native_core.isBound) {
throw new Error(
Expand Down Expand Up @@ -85,7 +48,8 @@ export { optimizeFunction, optimizeFunctionSync } from "./optimization";
export { wrapWithRootFrame, wrapWithRootFrameSync } from "./rootFrame";
export * from "./utils";
export * from "./walltime";
export type { InstrumentMode };
export type { InstrumentMode } from "./runnerMode";
export { getCodspeedRunnerMode, getInstrumentMode } from "./runnerMode";
export const InstrumentHooks = native_core.InstrumentHooks;

// Marker type constants, sourced from the native addon (which reads them from
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/introspection.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { writeFileSync } from "fs";
import path from "path";

import { getInstrumentMode } from ".";
import { getInstrumentMode } from "./runnerMode";

const CUSTOM_INTROSPECTION_EXIT_CODE = 0;

Expand Down Expand Up @@ -32,6 +32,15 @@ export const getV8Flags = () => {
}
if (nodeVersionMajor < 20) {
flags.push("--no-scavenge-task");
} else {
// V8 11.3 renamed --scavenge-task to --minor-gc-task
flags.push("--no-minor-gc-task");
}
if (nodeVersionMajor >= 24) {
// --no-opt is only an alias for --no-turbofan. Maglev is compiled out of
// Node < 24 but enabled by default from V8 13.6 on, where it keeps
// tiering up hot functions and cuts their instruction count ~4x.
flags.push("--no-maglev");
}

break;
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/native_core/linux_perf/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

static inline std::string
v8LocalStringToString(v8::Local<v8::String> v8String) {
std::string buffer(v8String->Utf8Length(v8::Isolate::GetCurrent()) + 1, 0);
v8String->WriteUtf8(v8::Isolate::GetCurrent(), &buffer[0],
v8String->Utf8Length(v8::Isolate::GetCurrent()) + 1);
// Sanitize name, removing unwanted \0 resulted from WriteUtf8
return std::string(buffer.c_str());
// Utf8Value NUL-terminates, so the c-string constructor stops at the first
// embedded NUL, as callers expect for symbol names. It yields nullptr when
// the conversion throws.
v8::String::Utf8Value value(v8::Isolate::GetCurrent(), v8String);
return *value ? std::string(*value) : std::string();
}

#endif // LINUX_PERF_UTILS_H
#endif // LINUX_PERF_UTILS_H
Loading
Loading