MCPcopy
hub / github.com/webpack/webpack / withCodSpeed

Function withCodSpeed

test/BenchmarkTestCases.benchmark.mjs:526–923  ·  view source on GitHub ↗
(bench)

Source from the content-addressed store, hash-verified

524 * @returns {Promise<Bench>} modifier bench
525 */
526const withCodSpeed = async (bench) => {
527 const codspeedRunnerMode = getCodspeedRunnerMode();
528
529 if (codspeedRunnerMode === "disabled") {
530 return bench;
531 }
532
533 const rawAdd = bench.add;
534 const uriMap = getOrCreateUriMap(bench);
535
536 const releaseClosuresAfterMeasure = codspeedRunnerMode === "memory";
537 const NO_OP_FN = () => {};
538
539 bench.add = (name, fn, options) => {
540 const callingFile = getCallingFile();
541 let uri = callingFile;
542 if (bench.name !== undefined) {
543 uri += `::${bench.name}`;
544 }
545 uri += `::${name}`;
546 uriMap.set(name, { uri, fn, options });
547 if (releaseClosuresAfterMeasure) {
548 return rawAdd.bind(bench)(name, NO_OP_FN, {});
549 }
550 return rawAdd.bind(bench)(name, fn, options);
551 };
552 const rootCallingFile = getCallingFile();
553
554 if (codspeedRunnerMode === "simulation" || codspeedRunnerMode === "memory") {
555 // Memory mode counts allocations in the instrumented region. With `--no-opt`
556 // (required by CodSpeed analysis mode), JIT stabilization isn't a factor,
557 // so 2 warmup runs are enough to populate require.cache, webpack lazy
558 // singletons, and V8 hidden classes. More warmup just bloats the heap with
559 // garbage that the pre-measurement drain has to clean up, raising the
560 // chance of an in-measurement GC and introducing variance across PRs that
561 // would otherwise touch identical code paths.
562 const warmupIterations =
563 codspeedRunnerMode === "memory" ? 2 : bench.iterations - 1;
564
565 const setupBenchRun = () => {
566 setupCore();
567 console.log(
568 `[CodSpeed] running with @codspeed/tinybench (${codspeedRunnerMode} mode, ${warmupIterations} warmup iterations)`
569 );
570 };
571 const finalizeBenchRun = () => {
572 teardownCore();
573 console.log(`[CodSpeed] Done running ${bench.tasks.length} benches.`);
574 return bench.tasks;
575 };
576
577 /**
578 * @param {Fn} fn function
579 * @param {boolean} isAsync true if async function, otherwise false
580 * @returns {() => void} function wrapped in codspeed root frame
581 */
582 const wrapFunctionWithFrame = (fn, isAsync) => {
583 if (isAsync) {

Calls 13

getOrCreateUriMapFunction · 0.85
getCallingFileFunction · 0.85
setupBenchRunFunction · 0.85
primeTaskAsyncFunction · 0.85
resolveFunction · 0.85
getTaskUriFunction · 0.85
runTaskAsyncFunction · 0.85
finalizeAsyncRunFunction · 0.85
primeTaskSyncFunction · 0.85
runTaskSyncFunction · 0.85
finalizeSyncRunFunction · 0.85
logMethod · 0.80

Tested by

no test coverage detected