mirror of https://github.com/webpack/webpack.git
Compare commits
6 Commits
d7f8858c59
...
2be6c6e0fa
| Author | SHA1 | Date |
|---|---|---|
|
|
2be6c6e0fa | |
|
|
59be3dc128 | |
|
|
154195fa4d | |
|
|
3c08fd105c | |
|
|
f508e8b705 | |
|
|
5c11f27b6b |
|
|
@ -214,7 +214,7 @@ jobs:
|
||||||
|
|
||||||
# Install old `jest` version and deps for legacy node versions
|
# Install old `jest` version and deps for legacy node versions
|
||||||
- run: |
|
- run: |
|
||||||
yarn upgrade jest@^27.5.0 jest-circus@^27.5.0 jest-cli@^27.5.0 jest-diff@^27.5.0 jest-environment-node@^27.5.0 jest-junit@^13.0.0 @types/jest@^27.4.0 pretty-format@^27.0.2 husky@^8.0.3 lint-staged@^13.2.1 cspell@^6.31.1 open-cli@^7.2.0 coffee-loader@^1.0.0 babel-loader@^8.1.0 style-loader@^2.0.0 css-loader@^5.0.1 less-loader@^8.1.1 mini-css-extract-plugin@^1.6.1 nyc@^15.1.0 --ignore-engines
|
yarn upgrade jest@^27.5.0 jest-circus@^27.5.0 jest-cli@^27.5.0 jest-diff@^27.5.0 jest-environment-node@^27.5.0 jest-junit@^13.0.0 @types/jest@^27.4.0 pretty-format@^27.0.2 husky@^8.0.3 lint-staged@^13.2.1 cspell@^6.31.1 open-cli@^7.2.0 coffee-loader@^1.0.0 babel-loader@^8.1.0 style-loader@^2.0.0 css-loader@^5.0.1 less-loader@^8.1.1 mini-css-extract-plugin@^1.6.1 nyc@^15.1.0 memfs@4.14.0 --ignore-engines
|
||||||
yarn --frozen-lockfile --ignore-engines
|
yarn --frozen-lockfile --ignore-engines
|
||||||
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x'
|
if: matrix.node-version == '10.x' || matrix.node-version == '12.x' || matrix.node-version == '14.x'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -284,6 +284,7 @@
|
||||||
"url's",
|
"url's",
|
||||||
"valign",
|
"valign",
|
||||||
"valtype",
|
"valtype",
|
||||||
|
"walltime",
|
||||||
"wasi",
|
"wasi",
|
||||||
"wasm",
|
"wasm",
|
||||||
"watchings",
|
"watchings",
|
||||||
|
|
@ -304,7 +305,6 @@
|
||||||
"commithash",
|
"commithash",
|
||||||
"formaters",
|
"formaters",
|
||||||
"akait",
|
"akait",
|
||||||
"Akait",
|
|
||||||
"evenstensberg",
|
"evenstensberg",
|
||||||
"Stensberg",
|
"Stensberg",
|
||||||
"ovflowd",
|
"ovflowd",
|
||||||
|
|
|
||||||
|
|
@ -115,7 +115,7 @@ class ImportMetaPlugin {
|
||||||
new ModuleDependencyWarning(
|
new ModuleDependencyWarning(
|
||||||
parser.state.module,
|
parser.state.module,
|
||||||
new CriticalDependencyWarning(
|
new CriticalDependencyWarning(
|
||||||
"Accessing import.meta directly is unsupported (only property access or destructuring is supported)"
|
"'import.meta' cannot be used as a standalone expression. For static analysis, its properties must be accessed directly (e.g., 'import.meta.url') or through destructuring."
|
||||||
),
|
),
|
||||||
/** @type {DependencyLocation} */ (metaProperty.loc)
|
/** @type {DependencyLocation} */ (metaProperty.loc)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
24
package.json
24
package.json
|
|
@ -111,16 +111,16 @@
|
||||||
"@babel/core": "^7.27.1",
|
"@babel/core": "^7.27.1",
|
||||||
"@babel/preset-react": "^7.27.1",
|
"@babel/preset-react": "^7.27.1",
|
||||||
"@codspeed/core": "^4.0.1",
|
"@codspeed/core": "^4.0.1",
|
||||||
"@eslint/js": "^9.29.0",
|
"@eslint/js": "^9.36.0",
|
||||||
"@eslint/markdown": "^7.1.0",
|
"@eslint/markdown": "^7.3.0",
|
||||||
"@stylistic/eslint-plugin": "^5.2.2",
|
"@stylistic/eslint-plugin": "^5.4.0",
|
||||||
"@types/glob-to-regexp": "^0.4.4",
|
"@types/glob-to-regexp": "^0.4.4",
|
||||||
"@types/graceful-fs": "^4.1.9",
|
"@types/graceful-fs": "^4.1.9",
|
||||||
"@types/jest": "^30.0.0",
|
"@types/jest": "^30.0.0",
|
||||||
"@types/mime-types": "^2.1.4",
|
"@types/mime-types": "^2.1.4",
|
||||||
"@types/node": "^24.1.0",
|
"@types/node": "^24.5.2",
|
||||||
"@types/xxhashjs": "^0.2.4",
|
"@types/xxhashjs": "^0.2.4",
|
||||||
"assemblyscript": "^0.28.5",
|
"assemblyscript": "^0.28.8",
|
||||||
"babel-loader": "^10.0.0",
|
"babel-loader": "^10.0.0",
|
||||||
"bundle-loader": "^0.5.6",
|
"bundle-loader": "^0.5.6",
|
||||||
"coffee-loader": "^5.0.0",
|
"coffee-loader": "^5.0.0",
|
||||||
|
|
@ -131,13 +131,13 @@
|
||||||
"date-fns": "^4.0.0",
|
"date-fns": "^4.0.0",
|
||||||
"es5-ext": "^0.10.53",
|
"es5-ext": "^0.10.53",
|
||||||
"es6-promise-polyfill": "^1.2.0",
|
"es6-promise-polyfill": "^1.2.0",
|
||||||
"eslint": "^9.29.0",
|
"eslint": "^9.36.0",
|
||||||
"eslint-config-prettier": "^10.1.1",
|
"eslint-config-prettier": "^10.1.1",
|
||||||
"eslint-config-webpack": "^4.5.1",
|
"eslint-config-webpack": "^4.5.1",
|
||||||
"eslint-plugin-import": "^2.32.0",
|
"eslint-plugin-import": "^2.32.0",
|
||||||
"eslint-plugin-jest": "^29.0.1",
|
"eslint-plugin-jest": "^29.0.1",
|
||||||
"eslint-plugin-jsdoc": "^51.2.3",
|
"eslint-plugin-jsdoc": "^51.2.3",
|
||||||
"eslint-plugin-n": "^17.21.0",
|
"eslint-plugin-n": "^17.23.1",
|
||||||
"eslint-plugin-prettier": "^5.5.0",
|
"eslint-plugin-prettier": "^5.5.0",
|
||||||
"eslint-plugin-unicorn": "^61.0.1",
|
"eslint-plugin-unicorn": "^61.0.1",
|
||||||
"file-loader": "^6.0.0",
|
"file-loader": "^6.0.0",
|
||||||
|
|
@ -146,11 +146,11 @@
|
||||||
"hash-wasm": "^4.9.0",
|
"hash-wasm": "^4.9.0",
|
||||||
"husky": "^9.0.11",
|
"husky": "^9.0.11",
|
||||||
"istanbul": "^0.4.5",
|
"istanbul": "^0.4.5",
|
||||||
"jest": "^30.1.2",
|
"jest": "^30.2.0",
|
||||||
"jest-circus": "^30.1.2",
|
"jest-circus": "^30.2.0",
|
||||||
"jest-cli": "^30.1.2",
|
"jest-cli": "^30.2.0",
|
||||||
"jest-diff": "^30.1.2",
|
"jest-diff": "^30.2.0",
|
||||||
"jest-environment-node": "^30.1.2",
|
"jest-environment-node": "^30.2.0",
|
||||||
"jest-junit": "^16.0.0",
|
"jest-junit": "^16.0.0",
|
||||||
"json-loader": "^0.5.7",
|
"json-loader": "^0.5.7",
|
||||||
"json5": "^2.1.3",
|
"json5": "^2.1.3",
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,16 @@ import fs from "fs/promises";
|
||||||
import { Session } from "inspector";
|
import { Session } from "inspector";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { fileURLToPath, pathToFileURL } from "url";
|
import { fileURLToPath, pathToFileURL } from "url";
|
||||||
|
import {
|
||||||
|
InstrumentHooks,
|
||||||
|
getCodspeedRunnerMode,
|
||||||
|
getGitDir,
|
||||||
|
getV8Flags,
|
||||||
|
mongoMeasurement,
|
||||||
|
optimizeFunction,
|
||||||
|
setupCore,
|
||||||
|
teardownCore
|
||||||
|
} from "@codspeed/core";
|
||||||
import { simpleGit } from "simple-git";
|
import { simpleGit } from "simple-git";
|
||||||
import { Bench, hrtimeNow } from "tinybench";
|
import { Bench, hrtimeNow } from "tinybench";
|
||||||
|
|
||||||
|
|
@ -12,32 +22,6 @@ const git = simpleGit(rootPath);
|
||||||
|
|
||||||
const REV_LIST_REGEXP = /^([a-f0-9]+)\s*([a-f0-9]+)\s*([a-f0-9]+)?\s*$/;
|
const REV_LIST_REGEXP = /^([a-f0-9]+)\s*([a-f0-9]+)\s*([a-f0-9]+)?\s*$/;
|
||||||
|
|
||||||
const getV8Flags = () => {
|
|
||||||
const nodeVersionMajor = Number.parseInt(
|
|
||||||
process.version.slice(1).split(".")[0],
|
|
||||||
10
|
|
||||||
);
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
return flags;
|
|
||||||
};
|
|
||||||
|
|
||||||
const checkV8Flags = () => {
|
const checkV8Flags = () => {
|
||||||
const requiredFlags = getV8Flags();
|
const requiredFlags = getV8Flags();
|
||||||
const actualFlags = process.execArgv;
|
const actualFlags = process.execArgv;
|
||||||
|
|
@ -248,6 +232,8 @@ for (const baselineInfo of baselineRevisions) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const baseOutputPath = path.join(__dirname, "js", "benchmark");
|
||||||
|
|
||||||
function buildConfiguration(
|
function buildConfiguration(
|
||||||
test,
|
test,
|
||||||
baseline,
|
baseline,
|
||||||
|
|
@ -385,105 +371,299 @@ const scenarios = [
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
const baseOutputPath = path.join(__dirname, "js", "benchmark");
|
function getStackTrace(belowFn) {
|
||||||
|
const oldLimit = Error.stackTraceLimit;
|
||||||
|
Error.stackTraceLimit = Infinity;
|
||||||
|
const dummyObject = {};
|
||||||
|
const v8Handler = Error.prepareStackTrace;
|
||||||
|
Error.prepareStackTrace = (dummyObject, v8StackTrace) => v8StackTrace;
|
||||||
|
Error.captureStackTrace(dummyObject, belowFn || getStackTrace);
|
||||||
|
const v8StackTrace = dummyObject.stack;
|
||||||
|
Error.prepareStackTrace = v8Handler;
|
||||||
|
Error.stackTraceLimit = oldLimit;
|
||||||
|
return v8StackTrace;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCallingFile() {
|
||||||
|
const stack = getStackTrace();
|
||||||
|
let callingFile = stack[2].getFileName(); // [here, withCodSpeed, actual caller]
|
||||||
|
const gitDir = getGitDir(callingFile);
|
||||||
|
if (gitDir === undefined) {
|
||||||
|
throw new Error("Could not find a git repository");
|
||||||
|
}
|
||||||
|
if (callingFile.startsWith("file://")) {
|
||||||
|
callingFile = fileURLToPath(callingFile);
|
||||||
|
}
|
||||||
|
return path.relative(gitDir, callingFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
const taskUriMap = new WeakMap();
|
||||||
|
|
||||||
|
function getOrCreateUriMap(bench) {
|
||||||
|
let uriMap = taskUriMap.get(bench);
|
||||||
|
if (!uriMap) {
|
||||||
|
uriMap = new Map();
|
||||||
|
taskUriMap.set(bench, uriMap);
|
||||||
|
}
|
||||||
|
return uriMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getTaskUri(bench, taskName, rootCallingFile) {
|
||||||
|
const uriMap = taskUriMap.get(bench);
|
||||||
|
return uriMap?.get(taskName) || `${rootCallingFile}::${taskName}`;
|
||||||
|
}
|
||||||
|
|
||||||
const withCodSpeed = async (/** @type {import("tinybench").Bench} */ bench) => {
|
const withCodSpeed = async (/** @type {import("tinybench").Bench} */ bench) => {
|
||||||
const { Measurement, getGitDir, mongoMeasurement, setupCore, teardownCore } =
|
const codspeedRunnerMode = getCodspeedRunnerMode();
|
||||||
await import("@codspeed/core");
|
|
||||||
|
|
||||||
if (!Measurement.isInstrumented()) {
|
if (codspeedRunnerMode === "disabled") {
|
||||||
const rawRun = bench.run;
|
|
||||||
bench.run = async () => {
|
|
||||||
console.warn(
|
|
||||||
`[CodSpeed] ${bench.tasks.length} benches detected but no instrumentation found, falling back to tinybench`
|
|
||||||
);
|
|
||||||
return await rawRun.bind(bench)();
|
|
||||||
};
|
|
||||||
return bench;
|
return bench;
|
||||||
}
|
}
|
||||||
|
|
||||||
const getStackTrace = (belowFn) => {
|
|
||||||
const oldLimit = Error.stackTraceLimit;
|
|
||||||
Error.stackTraceLimit = Infinity;
|
|
||||||
const dummyObject = {};
|
|
||||||
const v8Handler = Error.prepareStackTrace;
|
|
||||||
Error.prepareStackTrace = (dummyObject, v8StackTrace) => v8StackTrace;
|
|
||||||
Error.captureStackTrace(dummyObject, belowFn || getStackTrace);
|
|
||||||
const v8StackTrace = dummyObject.stack;
|
|
||||||
Error.prepareStackTrace = v8Handler;
|
|
||||||
Error.stackTraceLimit = oldLimit;
|
|
||||||
return v8StackTrace;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCallingFile = () => {
|
|
||||||
const stack = getStackTrace();
|
|
||||||
let callingFile = stack[2].getFileName(); // [here, withCodSpeed, actual caller]
|
|
||||||
const gitDir = getGitDir(callingFile);
|
|
||||||
if (gitDir === undefined) {
|
|
||||||
throw new Error("Could not find a git repository");
|
|
||||||
}
|
|
||||||
if (callingFile.startsWith("file://")) {
|
|
||||||
callingFile = fileURLToPath(callingFile);
|
|
||||||
}
|
|
||||||
return path.relative(gitDir, callingFile);
|
|
||||||
};
|
|
||||||
|
|
||||||
const rawAdd = bench.add;
|
const rawAdd = bench.add;
|
||||||
|
const uriMap = getOrCreateUriMap(bench);
|
||||||
bench.add = (name, fn, opts) => {
|
bench.add = (name, fn, opts) => {
|
||||||
const callingFile = getCallingFile();
|
const callingFile = getCallingFile();
|
||||||
const uri = `${callingFile}::${name}`;
|
let uri = callingFile;
|
||||||
const options = { ...opts, uri };
|
if (bench.name !== undefined) {
|
||||||
return rawAdd.bind(bench)(name, fn, options);
|
uri += `::${bench.name}`;
|
||||||
|
}
|
||||||
|
uri += `::${name}`;
|
||||||
|
uriMap.set(name, uri);
|
||||||
|
return rawAdd.bind(bench)(name, fn, opts);
|
||||||
};
|
};
|
||||||
const rootCallingFile = getCallingFile();
|
const rootCallingFile = getCallingFile();
|
||||||
bench.run = async function run() {
|
|
||||||
const iterations = bench.opts.iterations - 1;
|
if (codspeedRunnerMode === "instrumented") {
|
||||||
console.log("[CodSpeed] running");
|
const setupBenchRun = () => {
|
||||||
setupCore();
|
setupCore();
|
||||||
for (const task of bench.tasks) {
|
console.log(
|
||||||
await bench.opts.setup?.(task, "run");
|
"[CodSpeed] running with @codspeed/tinybench (instrumented mode)"
|
||||||
await task.fnOpts.beforeAll?.call(task);
|
);
|
||||||
const samples = [];
|
};
|
||||||
async function iteration() {
|
const finalizeBenchRun = () => {
|
||||||
try {
|
teardownCore();
|
||||||
await task.fnOpts.beforeEach?.call(task, "run");
|
console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
|
||||||
const start = bench.opts.now();
|
return bench.tasks;
|
||||||
await task.fn();
|
};
|
||||||
samples.push(bench.opts.now() - start || 0);
|
|
||||||
await task.fnOpts.afterEach?.call(this, "run");
|
const wrapFunctionWithFrame = (fn, isAsync) => {
|
||||||
} catch (err) {
|
if (isAsync) {
|
||||||
if (bench.opts.throws) {
|
return async function __codspeed_root_frame__() {
|
||||||
throw err;
|
await fn();
|
||||||
}
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return function __codspeed_root_frame__() {
|
||||||
|
fn();
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const logTaskCompletion = (uri, status) => {
|
||||||
|
console.log(`[CodSpeed] ${status} ${uri}`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const taskCompletionMessage = () =>
|
||||||
|
InstrumentHooks.isInstrumented() ? "Measured" : "Checked";
|
||||||
|
|
||||||
|
const iterationAsync = async (task) => {
|
||||||
|
try {
|
||||||
|
await task.fnOpts.beforeEach?.call(task, "run");
|
||||||
|
const start = bench.opts.now();
|
||||||
|
await task.fn();
|
||||||
|
const end = bench.opts.now() - start || 0;
|
||||||
|
await task.fnOpts.afterEach?.call(this, "run");
|
||||||
|
return [start, end];
|
||||||
|
} catch (err) {
|
||||||
|
if (bench.opts.throws) {
|
||||||
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (samples.length < iterations) {
|
};
|
||||||
await iteration();
|
|
||||||
}
|
|
||||||
// Codspeed Measure
|
|
||||||
const uri =
|
|
||||||
task.opts && "uri" in task.options
|
|
||||||
? task.opts.uri
|
|
||||||
: `${rootCallingFile}::${task.name}`;
|
|
||||||
await task.fnOpts.beforeEach?.call(task);
|
|
||||||
await mongoMeasurement.start(uri);
|
|
||||||
await (async function __codspeed_root_frame__() {
|
|
||||||
Measurement.startInstrumentation();
|
|
||||||
await task.fn();
|
|
||||||
Measurement.stopInstrumentation(uri);
|
|
||||||
})();
|
|
||||||
await mongoMeasurement.stop(uri);
|
|
||||||
await task.fnOpts.afterEach?.call(task);
|
|
||||||
console.log(`[Codspeed] ✔ Measured ${uri}`);
|
|
||||||
await task.fnOpts.afterAll?.call(task);
|
|
||||||
|
|
||||||
await bench.opts.teardown?.(task, "run");
|
const wrapWithInstrumentHooksAsync = async (fn, uri) => {
|
||||||
task.processRunResult({ latencySamples: samples });
|
InstrumentHooks.startBenchmark();
|
||||||
|
const result = await fn();
|
||||||
|
InstrumentHooks.stopBenchmark();
|
||||||
|
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
function printStatus(fn) {
|
||||||
|
const status = eval("%GetOptimizationStatus(fn)");
|
||||||
|
console.log(status.toString(2).padStart(12, "0"));
|
||||||
|
|
||||||
|
if (status & (1 << 0)) {
|
||||||
|
console.log("is function");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 1)) {
|
||||||
|
console.log("is never optimized");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 2)) {
|
||||||
|
console.log("is always optimized");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 3)) {
|
||||||
|
console.log("is maybe deoptimized");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 4)) {
|
||||||
|
console.log("is optimized");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 5)) {
|
||||||
|
console.log("is optimized by TurboFan");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 6)) {
|
||||||
|
console.log("is interpreted");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 7)) {
|
||||||
|
console.log("is marked for optimization");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 8)) {
|
||||||
|
console.log("is marked for concurrent optimization");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 9)) {
|
||||||
|
console.log("is optimizing concurrently");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 10)) {
|
||||||
|
console.log("is executing");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status & (1 << 11)) {
|
||||||
|
console.log("topmost frame is turbo fanned");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
teardownCore();
|
|
||||||
console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
|
const runTaskAsync = async (task, uri) => {
|
||||||
return bench.tasks;
|
const { fnOpts, fn } = task;
|
||||||
};
|
|
||||||
|
// Custom setup
|
||||||
|
await bench.opts.setup?.(task, "run");
|
||||||
|
|
||||||
|
await fnOpts?.beforeAll?.call(task, "run");
|
||||||
|
|
||||||
|
// Custom warmup
|
||||||
|
const samples = [];
|
||||||
|
while (samples.length < bench.opts.iterations - 1) {
|
||||||
|
samples.push(await iterationAsync(task));
|
||||||
|
}
|
||||||
|
|
||||||
|
const toRun = async () => {
|
||||||
|
await fnOpts?.beforeEach?.call(task, "run");
|
||||||
|
await fn();
|
||||||
|
await fnOpts?.afterEach?.call(task, "run");
|
||||||
|
};
|
||||||
|
|
||||||
|
await optimizeFunction(toRun);
|
||||||
|
|
||||||
|
console.log("optimize", printStatus(toRun));
|
||||||
|
|
||||||
|
await fnOpts?.beforeEach?.call(task, "run");
|
||||||
|
await mongoMeasurement.start(uri);
|
||||||
|
global.gc?.();
|
||||||
|
await wrapWithInstrumentHooksAsync(wrapFunctionWithFrame(fn, true), uri);
|
||||||
|
await mongoMeasurement.stop(uri);
|
||||||
|
await fnOpts?.afterEach?.call(task, "run");
|
||||||
|
console.log(`[Codspeed] ✔ Measured ${uri}`);
|
||||||
|
await fnOpts?.afterAll?.call(task, "run");
|
||||||
|
|
||||||
|
// Custom teardown
|
||||||
|
await bench.opts.teardown?.(task, "run");
|
||||||
|
|
||||||
|
logTaskCompletion(uri, taskCompletionMessage());
|
||||||
|
};
|
||||||
|
|
||||||
|
const iteration = (task) => {
|
||||||
|
try {
|
||||||
|
task.fnOpts.beforeEach?.call(task, "run");
|
||||||
|
const start = bench.opts.now();
|
||||||
|
task.fn();
|
||||||
|
const end = bench.opts.now() - start || 0;
|
||||||
|
task.fnOpts.afterEach?.call(this, "run");
|
||||||
|
return [start, end];
|
||||||
|
} catch (err) {
|
||||||
|
if (bench.opts.throws) {
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const wrapWithInstrumentHooks = (fn, uri) => {
|
||||||
|
InstrumentHooks.startBenchmark();
|
||||||
|
const result = fn();
|
||||||
|
InstrumentHooks.stopBenchmark();
|
||||||
|
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const runTaskSync = (task, uri) => {
|
||||||
|
const { fnOpts, fn } = task;
|
||||||
|
|
||||||
|
// Custom setup
|
||||||
|
bench.opts.setup?.(task, "run");
|
||||||
|
|
||||||
|
fnOpts?.beforeAll?.call(task, "run");
|
||||||
|
|
||||||
|
// Custom warmup
|
||||||
|
const samples = [];
|
||||||
|
while (samples.length < bench.opts.iterations - 1) {
|
||||||
|
samples.push(iteration(task));
|
||||||
|
}
|
||||||
|
|
||||||
|
fnOpts?.beforeEach?.call(task, "run");
|
||||||
|
|
||||||
|
wrapWithInstrumentHooks(wrapFunctionWithFrame(fn, false), uri);
|
||||||
|
|
||||||
|
fnOpts?.afterEach?.call(task, "run");
|
||||||
|
console.log(`[Codspeed] ✔ Measured ${uri}`);
|
||||||
|
fnOpts?.afterAll?.call(task, "run");
|
||||||
|
|
||||||
|
// Custom teardown
|
||||||
|
bench.opts.teardown?.(task, "run");
|
||||||
|
|
||||||
|
logTaskCompletion(uri, taskCompletionMessage());
|
||||||
|
};
|
||||||
|
|
||||||
|
const finalizeAsyncRun = () => {
|
||||||
|
finalizeBenchRun();
|
||||||
|
};
|
||||||
|
const finalizeSyncRun = () => {
|
||||||
|
finalizeBenchRun();
|
||||||
|
};
|
||||||
|
|
||||||
|
bench.run = async () => {
|
||||||
|
setupBenchRun();
|
||||||
|
|
||||||
|
for (const task of bench.tasks) {
|
||||||
|
const uri = getTaskUri(task.bench, task.name, rootCallingFile);
|
||||||
|
await runTaskAsync(task, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalizeAsyncRun();
|
||||||
|
};
|
||||||
|
|
||||||
|
bench.runSync = () => {
|
||||||
|
setupBenchRun();
|
||||||
|
|
||||||
|
for (const task of bench.tasks) {
|
||||||
|
const uri = getTaskUri(task.bench, task.name, rootCallingFile);
|
||||||
|
runTaskSync(task, uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
return finalizeSyncRun();
|
||||||
|
};
|
||||||
|
} else if (codspeedRunnerMode === "walltime") {
|
||||||
|
// We don't need it
|
||||||
|
}
|
||||||
|
|
||||||
return bench;
|
return bench;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -495,7 +675,6 @@ const bench = await withCodSpeed(
|
||||||
warmupIterations: 2,
|
warmupIterations: 2,
|
||||||
iterations: 8,
|
iterations: 8,
|
||||||
setup(task, mode) {
|
setup(task, mode) {
|
||||||
global.gc();
|
|
||||||
console.log(`Setup (${mode} mode): ${task.name}`);
|
console.log(`Setup (${mode} mode): ${task.name}`);
|
||||||
},
|
},
|
||||||
teardown(task, mode) {
|
teardown(task, mode) {
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
module.exports = [[/Critical dependency: Accessing import\.meta/]];
|
module.exports = [
|
||||||
|
[
|
||||||
|
/Critical dependency: 'import\.meta' cannot be used as a standalone expression\. For static analysis, its properties must be accessed directly \(e\.g\., 'import\.meta\.url'\) or through destructuring\./
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,6 @@
|
||||||
|
|
||||||
module.exports = [
|
module.exports = [
|
||||||
[
|
[
|
||||||
/Accessing import.meta directly is unsupported \(only property access or destructuring is supported\)/
|
/'import\.meta' cannot be used as a standalone expression\. For static analysis, its properties must be accessed directly \(e\.g\., 'import\.meta\.url'\) or through destructuring\./
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue