mirror of https://github.com/webpack/webpack.git
Compare commits
5 Commits
7bb607d138
...
c12824d4a9
Author | SHA1 | Date |
---|---|---|
|
c12824d4a9 | |
|
9f98d803c0 | |
|
8804459884 | |
|
bc91301142 | |
|
d5b4b50c10 |
|
@ -97,7 +97,7 @@ jobs:
|
|||
- run: yarn link webpack --frozen-lockfile
|
||||
|
||||
- name: Run benchmarks
|
||||
uses: CodSpeedHQ/action@653fdc30e6c40ffd9739e40c8a0576f4f4523ca1 # v4.0.1
|
||||
uses: CodSpeedHQ/action@3959e9e296ef25296e93e32afcc97196f966e57f # v4.1.0
|
||||
with:
|
||||
run: yarn benchmark --ci
|
||||
mode: "instrumentation"
|
||||
|
|
|
@ -284,6 +284,7 @@
|
|||
"url's",
|
||||
"valign",
|
||||
"valtype",
|
||||
"walltime",
|
||||
"wasi",
|
||||
"wasm",
|
||||
"watchings",
|
||||
|
@ -304,7 +305,6 @@
|
|||
"commithash",
|
||||
"formaters",
|
||||
"akait",
|
||||
"Akait",
|
||||
"evenstensberg",
|
||||
"Stensberg",
|
||||
"ovflowd",
|
||||
|
|
|
@ -3349,7 +3349,6 @@ export interface JavascriptParserOptions {
|
|||
* Set the inner regular expression for partial dynamic dependencies.
|
||||
*/
|
||||
wrappedContextRegExp?: RegExp;
|
||||
[k: string]: any;
|
||||
}
|
||||
/**
|
||||
* Generator options for json modules.
|
||||
|
|
|
@ -1988,6 +1988,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|||
? /** @type {NameForCondition} */ (originModule.nameForCondition())
|
||||
: "",
|
||||
issuerLayer: originModule ? originModule.layer : null,
|
||||
issuerDependency: originModule ? originModule.issuerDependencyType : null,
|
||||
compiler: this.compiler.name,
|
||||
...contextInfo
|
||||
},
|
||||
|
|
|
@ -335,6 +335,7 @@ class NormalModule extends Module {
|
|||
constructor({
|
||||
layer,
|
||||
type,
|
||||
issuerDependencyType,
|
||||
request,
|
||||
userRequest,
|
||||
rawRequest,
|
||||
|
@ -352,6 +353,7 @@ class NormalModule extends Module {
|
|||
}) {
|
||||
super(type, context || getContext(resource), layer);
|
||||
|
||||
this.issuerDependencyType = issuerDependencyType;
|
||||
// Info from Factory
|
||||
/** @type {string} */
|
||||
this.request = request;
|
||||
|
|
|
@ -514,6 +514,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
context,
|
||||
dependencies,
|
||||
dependencyType,
|
||||
issuerDependencyType,
|
||||
request,
|
||||
attributes,
|
||||
resolveOptions,
|
||||
|
@ -776,6 +777,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
Object.assign(data.createData, {
|
||||
layer:
|
||||
layer === undefined ? contextInfo.issuerLayer || null : layer,
|
||||
issuerDependencyType: issuerDependencyType,
|
||||
request: stringifyLoadersAndResource(
|
||||
allLoaders,
|
||||
resourceData.resource
|
||||
|
@ -864,7 +866,6 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
};
|
||||
continueCallback();
|
||||
}
|
||||
|
||||
// resource without scheme and with path
|
||||
else {
|
||||
const normalResolver = this.getResolver(
|
||||
|
@ -875,6 +876,13 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
"dependencyType",
|
||||
dependencyType
|
||||
)
|
||||
: resolveOptions,
|
||||
issuerDependencyType
|
||||
? cachedSetProperty(
|
||||
resolveOptions || EMPTY_RESOLVE_OPTIONS,
|
||||
"issuerDependency",
|
||||
issuerDependencyType
|
||||
)
|
||||
: resolveOptions
|
||||
);
|
||||
this.resolveResource(
|
||||
|
@ -972,6 +980,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
(dependency).attributes;
|
||||
const dependencyType = dependency.category || "";
|
||||
const contextInfo = data.contextInfo;
|
||||
const issuerDependencyType = dependency.issuerCategory || contextInfo.issuerDependency || null;
|
||||
const fileDependencies = new LazySet();
|
||||
const missingDependencies = new LazySet();
|
||||
const contextDependencies = new LazySet();
|
||||
|
@ -984,6 +993,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
attributes,
|
||||
dependencies,
|
||||
dependencyType,
|
||||
issuerDependencyType,
|
||||
fileDependencies,
|
||||
missingDependencies,
|
||||
contextDependencies,
|
||||
|
@ -1432,10 +1442,11 @@ If changing the source code is not an option there is also a resolve options cal
|
|||
/**
|
||||
* @param {Parameters<ResolverFactory["get"]>[0]} type type of resolver
|
||||
* @param {Parameters<ResolverFactory["get"]>[1]=} resolveOptions options
|
||||
* @param {Parameters<ResolverFactory["get"]>[1]=} issuerResolveOptions options
|
||||
* @returns {ReturnType<ResolverFactory["get"]>} the resolver
|
||||
*/
|
||||
getResolver(type, resolveOptions) {
|
||||
return this.resolverFactory.get(type, resolveOptions);
|
||||
getResolver(type, resolveOptions, issuerResolveOptions) {
|
||||
return this.resolverFactory.get(type, resolveOptions, issuerResolveOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,9 +32,13 @@ const EMPTY_RESOLVE_OPTIONS = {};
|
|||
|
||||
/**
|
||||
* @param {ResolveOptionsWithDependencyType} resolveOptionsWithDepType enhanced options
|
||||
* @param {ResolveOptionsWithDependencyType} issuerResolveOptions enhanced options
|
||||
* @returns {ResolveOptions} merged options
|
||||
*/
|
||||
const convertToResolveOptions = (resolveOptionsWithDepType) => {
|
||||
const convertToResolveOptions = (
|
||||
resolveOptionsWithDepType,
|
||||
issuerResolveOptions
|
||||
) => {
|
||||
const { dependencyType, plugins, ...remaining } = resolveOptionsWithDepType;
|
||||
|
||||
// check type compat
|
||||
|
@ -58,10 +62,24 @@ const convertToResolveOptions = (resolveOptionsWithDepType) => {
|
|||
/** @type {Partial<ResolveOptionsWithDependencyType> & Pick<ResolveOptionsWithDependencyType, "fileSystem">} */ (
|
||||
partialOptions
|
||||
);
|
||||
const { issuerDependency } = issuerResolveOptions;
|
||||
|
||||
const resolvedByDependency = resolveByProperty(
|
||||
options,
|
||||
"byDependency",
|
||||
dependencyType
|
||||
);
|
||||
|
||||
return /** @type {ResolveOptions} */ (
|
||||
// byIssuerDependencyType
|
||||
removeOperations(
|
||||
resolveByProperty(options, "byDependency", dependencyType),
|
||||
issuerDependency
|
||||
? resolveByProperty(
|
||||
resolvedByDependency,
|
||||
"byIssuerDependency",
|
||||
issuerDependency
|
||||
)
|
||||
: resolvedByDependency,
|
||||
// Keep the `unsafeCache` because it can be a `Proxy`
|
||||
["unsafeCache"]
|
||||
)
|
||||
|
@ -93,44 +111,55 @@ module.exports = class ResolverFactory {
|
|||
/**
|
||||
* @param {string} type type of resolver
|
||||
* @param {ResolveOptionsWithDependencyType=} resolveOptions options
|
||||
* @param {ResolveOptionsWithDependencyType=} issuerResolveOptions options
|
||||
* @returns {ResolverWithOptions} the resolver
|
||||
*/
|
||||
get(type, resolveOptions = EMPTY_RESOLVE_OPTIONS) {
|
||||
let typedCaches = this.cache.get(type);
|
||||
if (!typedCaches) {
|
||||
typedCaches = {
|
||||
direct: new WeakMap(),
|
||||
stringified: new Map()
|
||||
};
|
||||
this.cache.set(type, typedCaches);
|
||||
}
|
||||
const cachedResolver = typedCaches.direct.get(resolveOptions);
|
||||
if (cachedResolver) {
|
||||
return cachedResolver;
|
||||
}
|
||||
const ident = JSON.stringify(resolveOptions);
|
||||
const resolver = typedCaches.stringified.get(ident);
|
||||
if (resolver) {
|
||||
typedCaches.direct.set(resolveOptions, resolver);
|
||||
return resolver;
|
||||
}
|
||||
const newResolver = this._create(type, resolveOptions);
|
||||
typedCaches.direct.set(resolveOptions, newResolver);
|
||||
typedCaches.stringified.set(ident, newResolver);
|
||||
get(
|
||||
type,
|
||||
resolveOptions = EMPTY_RESOLVE_OPTIONS,
|
||||
issuerResolveOptions = EMPTY_RESOLVE_OPTIONS
|
||||
) {
|
||||
// let typedCaches = this.cache.get(type);
|
||||
// if (!typedCaches) {
|
||||
// typedCaches = {
|
||||
// direct: new WeakMap(),
|
||||
// stringified: new Map()
|
||||
// };
|
||||
// this.cache.set(type, typedCaches);
|
||||
// }
|
||||
// const cachedResolver = typedCaches.direct.get(resolveOptions);
|
||||
// if (cachedResolver) {
|
||||
// return cachedResolver;
|
||||
// }
|
||||
// const ident = JSON.stringify(resolveOptions);
|
||||
// const resolver = typedCaches.stringified.get(ident);
|
||||
// if (resolver) {
|
||||
// typedCaches.direct.set(resolveOptions, resolver);
|
||||
// return resolver;
|
||||
// }
|
||||
const newResolver = this._create(
|
||||
type,
|
||||
resolveOptions,
|
||||
issuerResolveOptions
|
||||
);
|
||||
// typedCaches.direct.set(resolveOptions, newResolver);
|
||||
// typedCaches.stringified.set(ident, newResolver);
|
||||
return newResolver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} type type of resolver
|
||||
* @param {ResolveOptionsWithDependencyType} resolveOptionsWithDepType options
|
||||
* @param {ResolveOptionsWithIssuerDependencyType} issuerResolveOptions options
|
||||
* @returns {ResolverWithOptions} the resolver
|
||||
*/
|
||||
_create(type, resolveOptionsWithDepType) {
|
||||
_create(type, resolveOptionsWithDepType, issuerResolveOptions) {
|
||||
/** @type {ResolveOptionsWithDependencyType} */
|
||||
const originalResolveOptions = { ...resolveOptionsWithDepType };
|
||||
|
||||
const resolveOptions = convertToResolveOptions(
|
||||
this.hooks.resolveOptions.for(type).call(resolveOptionsWithDepType)
|
||||
this.hooks.resolveOptions.for(type).call(resolveOptionsWithDepType),
|
||||
issuerResolveOptions
|
||||
);
|
||||
const resolver = /** @type {ResolverWithOptions} */ (
|
||||
Factory.createResolver(resolveOptions)
|
||||
|
|
|
@ -1795,12 +1795,17 @@ const getResolveDefaults = ({
|
|||
conditionNames: ["require", "module", "..."],
|
||||
extensions: [...jsExtensions]
|
||||
});
|
||||
/** @type {() => ResolveOptions} */
|
||||
const esmDeps = () => ({
|
||||
/** @type {(options?: { worker?: boolean }) => ResolveOptions} */
|
||||
const esmDeps = ({ worker } = {}) => ({
|
||||
aliasFields: browserField ? ["browser"] : [],
|
||||
mainFields: browserField ? ["browser", "module", "..."] : ["module", "..."],
|
||||
conditionNames: ["import", "module", "..."],
|
||||
extensions: [...jsExtensions]
|
||||
conditionNames: [...(worker ? ["worker"] : []), "import", "module", "..."],
|
||||
extensions: [...jsExtensions],
|
||||
byIssuerDependency: {
|
||||
worker: {
|
||||
conditionNames: ["worker", "import", "module", "..."]
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
/** @type {ResolveOptions} */
|
||||
|
@ -1823,7 +1828,7 @@ const getResolveDefaults = ({
|
|||
preferRelative: true
|
||||
},
|
||||
worker: {
|
||||
...esmDeps(),
|
||||
...esmDeps({ worker: true }),
|
||||
preferRelative: true
|
||||
},
|
||||
commonjs: cjsDeps(),
|
||||
|
|
|
@ -58,6 +58,10 @@ class WorkerDependency extends ModuleDependency {
|
|||
return "worker";
|
||||
}
|
||||
|
||||
get issuerCategory() {
|
||||
return "worker";
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the hash
|
||||
* @param {Hash} hash hash to be updated
|
||||
|
|
|
@ -110,7 +110,7 @@
|
|||
"devDependencies": {
|
||||
"@babel/core": "^7.27.1",
|
||||
"@babel/preset-react": "^7.27.1",
|
||||
"@codspeed/core": "^4.0.1",
|
||||
"@codspeed/core": "^5.0.1",
|
||||
"@eslint/js": "^9.36.0",
|
||||
"@eslint/markdown": "^7.3.0",
|
||||
"@stylistic/eslint-plugin": "^5.4.0",
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1786,7 +1786,7 @@
|
|||
"JavascriptParserOptions": {
|
||||
"description": "Parser options for javascript modules.",
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"amd": {
|
||||
"$ref": "#/definitions/Amd"
|
||||
|
|
|
@ -3,6 +3,15 @@ import fs from "fs/promises";
|
|||
import { Session } from "inspector";
|
||||
import path from "path";
|
||||
import { fileURLToPath, pathToFileURL } from "url";
|
||||
import {
|
||||
InstrumentHooks,
|
||||
getCodspeedRunnerMode,
|
||||
getGitDir,
|
||||
getV8Flags,
|
||||
mongoMeasurement,
|
||||
setupCore,
|
||||
teardownCore
|
||||
} from "@codspeed/core";
|
||||
import { simpleGit } from "simple-git";
|
||||
import { Bench, hrtimeNow } from "tinybench";
|
||||
|
||||
|
@ -12,32 +21,6 @@ const git = simpleGit(rootPath);
|
|||
|
||||
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 requiredFlags = getV8Flags();
|
||||
const actualFlags = process.execArgv;
|
||||
|
@ -248,6 +231,8 @@ for (const baselineInfo of baselineRevisions) {
|
|||
}
|
||||
}
|
||||
|
||||
const baseOutputPath = path.join(__dirname, "js", "benchmark");
|
||||
|
||||
function buildConfiguration(
|
||||
test,
|
||||
baseline,
|
||||
|
@ -385,105 +370,239 @@ 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 { Measurement, getGitDir, mongoMeasurement, setupCore, teardownCore } =
|
||||
await import("@codspeed/core");
|
||||
const codspeedRunnerMode = getCodspeedRunnerMode();
|
||||
|
||||
if (!Measurement.isInstrumented()) {
|
||||
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)();
|
||||
};
|
||||
if (codspeedRunnerMode === "disabled") {
|
||||
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 uriMap = getOrCreateUriMap(bench);
|
||||
bench.add = (name, fn, opts) => {
|
||||
const callingFile = getCallingFile();
|
||||
const uri = `${callingFile}::${name}`;
|
||||
const options = { ...opts, uri };
|
||||
return rawAdd.bind(bench)(name, fn, options);
|
||||
let uri = callingFile;
|
||||
if (bench.name !== undefined) {
|
||||
uri += `::${bench.name}`;
|
||||
}
|
||||
uri += `::${name}`;
|
||||
uriMap.set(name, uri);
|
||||
return rawAdd.bind(bench)(name, fn, opts);
|
||||
};
|
||||
const rootCallingFile = getCallingFile();
|
||||
bench.run = async function run() {
|
||||
const iterations = bench.opts.iterations - 1;
|
||||
console.log("[CodSpeed] running");
|
||||
setupCore();
|
||||
for (const task of bench.tasks) {
|
||||
await bench.opts.setup?.(task, "run");
|
||||
await task.fnOpts.beforeAll?.call(task);
|
||||
const samples = [];
|
||||
async function iteration() {
|
||||
try {
|
||||
await task.fnOpts.beforeEach?.call(task, "run");
|
||||
const start = bench.opts.now();
|
||||
await task.fn();
|
||||
samples.push(bench.opts.now() - start || 0);
|
||||
await task.fnOpts.afterEach?.call(this, "run");
|
||||
} catch (err) {
|
||||
if (bench.opts.throws) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (codspeedRunnerMode === "instrumented") {
|
||||
const setupBenchRun = () => {
|
||||
setupCore();
|
||||
console.log(
|
||||
"[CodSpeed] running with @codspeed/tinybench (instrumented mode)"
|
||||
);
|
||||
};
|
||||
const finalizeBenchRun = () => {
|
||||
teardownCore();
|
||||
console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
|
||||
return bench.tasks;
|
||||
};
|
||||
|
||||
const wrapFunctionWithFrame = (fn, isAsync) => {
|
||||
if (isAsync) {
|
||||
return async function __codspeed_root_frame__() {
|
||||
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);
|
||||
};
|
||||
|
||||
const wrapWithInstrumentHooksAsync = async (fn, uri) => {
|
||||
InstrumentHooks.startBenchmark();
|
||||
const result = await fn();
|
||||
InstrumentHooks.stopBenchmark();
|
||||
InstrumentHooks.setExecutedBenchmark(process.pid, uri);
|
||||
return result;
|
||||
};
|
||||
|
||||
const runTaskAsync = async (task, uri) => {
|
||||
const { fnOpts, fn } = task;
|
||||
|
||||
// Custom setup
|
||||
await bench.opts.setup?.(task, "run");
|
||||
|
||||
await fnOpts?.beforeAll?.call(task, "run");
|
||||
|
||||
// Custom warmup
|
||||
// We don't run `optimizeFunction` because our function is never optimized, instead we just warmup webpack
|
||||
const samples = [];
|
||||
|
||||
while (samples.length < bench.opts.iterations - 1) {
|
||||
samples.push(await iterationAsync(task));
|
||||
}
|
||||
|
||||
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");
|
||||
task.processRunResult({ latencySamples: samples });
|
||||
}
|
||||
teardownCore();
|
||||
console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
|
||||
return bench.tasks;
|
||||
};
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
@ -495,7 +614,6 @@ const bench = await withCodSpeed(
|
|||
warmupIterations: 2,
|
||||
iterations: 8,
|
||||
setup(task, mode) {
|
||||
global.gc();
|
||||
console.log(`Setup (${mode} mode): ${task.name}`);
|
||||
},
|
||||
teardown(task, mode) {
|
||||
|
|
|
@ -8195,8 +8195,6 @@ declare class JavascriptParser extends ParserClass {
|
|||
* Parser options for javascript modules.
|
||||
*/
|
||||
declare interface JavascriptParserOptions {
|
||||
[index: string]: any;
|
||||
|
||||
/**
|
||||
* Set the value of `require.amd` and `define.amd`. Or disable AMD support.
|
||||
*/
|
||||
|
|
12
yarn.lock
12
yarn.lock
|
@ -332,14 +332,14 @@
|
|||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||
|
||||
"@codspeed/core@^4.0.1":
|
||||
version "4.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@codspeed/core/-/core-4.0.1.tgz#91049cce17b8c1d1b4b6cbc481f5ddc1145d6e1e"
|
||||
integrity sha512-fJ53arfgtzCDZa8DuGJhpTZ3Ll9A1uW5nQ2jSJnfO4Hl5MRD2cP8P4vPvIUAGbdbjwCxR1jat6cW8OloMJkJXw==
|
||||
"@codspeed/core@^5.0.1":
|
||||
version "5.0.1"
|
||||
resolved "https://registry.yarnpkg.com/@codspeed/core/-/core-5.0.1.tgz#6145c898a86a6d56a169611c3e9657a8b97c7642"
|
||||
integrity sha512-4g5ZyFAin8QywK4+0FK1uXG3GLRPu0oc3xbP+7OUhhFxbwpzFuaJtKmnTofMqLy9/pHH6Bl/7H0/DTVH3cpFkA==
|
||||
dependencies:
|
||||
axios "^1.4.0"
|
||||
find-up "^6.3.0"
|
||||
form-data "^4.0.0"
|
||||
form-data "^4.0.4"
|
||||
node-gyp-build "^4.6.0"
|
||||
|
||||
"@cspell/cspell-bundled-dicts@9.1.3":
|
||||
|
@ -3878,7 +3878,7 @@ fork-ts-checker-webpack-plugin@^9.0.2:
|
|||
semver "^7.3.5"
|
||||
tapable "^2.2.1"
|
||||
|
||||
form-data@^4.0.0, form-data@^4.0.4:
|
||||
form-data@^4.0.4:
|
||||
version "4.0.4"
|
||||
resolved "https://registry.yarnpkg.com/form-data/-/form-data-4.0.4.tgz#784cdcce0669a9d68e94d11ac4eea98088edd2c4"
|
||||
integrity sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==
|
||||
|
|
Loading…
Reference in New Issue