MCPcopy
hub / github.com/webpack/webpack / runTaskAsync

Function runTaskAsync

test/BenchmarkTestCases.benchmark.mjs:647–717  ·  view source on GitHub ↗
(task, name, uri)

Source from the content-addressed store, hash-verified

645 * @param {string} uri URI
646 */
647 const runTaskAsync = async (task, name, uri) => {
648 let { fn, options } =
649 /** @type {TaskMeta} */
650 (uriMap.get(name));
651
652 // Custom setup
653 await bench.setup?.(task, "run");
654
655 await options?.beforeAll?.call(task, "run");
656
657 if (
658 codspeedRunnerMode === "simulation" ||
659 codspeedRunnerMode === "memory"
660 ) {
661 // Custom warmup
662 // We don't run `optimizeFunction` because our function is never optimized, instead we just warmup webpack.
663 // Memory mode also needs warmup so the first measured sample isn't
664 // polluted by module loading, lazy webpack init, and JIT shape transitions.
665 const samples = [];
666
667 while (samples.length < warmupIterations) {
668 samples.push(await iterationAsync(task, name));
669 }
670 }
671
672 await options?.beforeEach?.call(task, "run");
673 await mongoMeasurement.start(uri);
674 // Drain heap before the instrumented region so allocations from the
675 // warmup runs aren't attributed to the measured sample (especially
676 // under massif). One GC can leave promoted-but-unreachable objects
677 // pending finalization; finalizers themselves can allocate. Loop
678 // `gc -> microtask` three times so each GC's finalizers get a chance
679 // to run and any garbage they produce is collected on the next pass,
680 // then drain pending IO with `setImmediate`, then one final GC to
681 // catch anything the IO callbacks left behind.
682 for (let i = 0; i < 3; i++) {
683 global.gc?.();
684 await new Promise((resolve) => {
685 queueMicrotask(() => resolve(undefined));
686 });
687 }
688 await new Promise((resolve) => {
689 setImmediate(resolve);
690 });
691 global.gc?.();
692 await wrapWithInstrumentHooksAsync(wrapFunctionWithFrame(fn, true), uri);
693 await mongoMeasurement.stop(uri);
694 await options?.afterEach?.call(task, "run");
695 console.log(`[Codspeed] ✔ Measured ${uri}`);
696 await options?.afterAll?.call(task, "run");
697
698 // Custom teardown
699 await bench.teardown?.(task, "run");
700
701 logTaskCompletion(uri, taskCompletionMessage());
702
703 // Release this task's closures
704 fn = NO_OP_FN;

Callers 1

withCodSpeedFunction · 0.85

Calls 12

iterationAsyncFunction · 0.85
resolveFunction · 0.85
wrapFunctionWithFrameFunction · 0.85
logTaskCompletionFunction · 0.85
taskCompletionMessageFunction · 0.85
stopMethod · 0.80
logMethod · 0.80
getMethod · 0.45
callMethod · 0.45
pushMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected