Skip to content

Commit

Permalink
Merge pull request #16894 from webpack/thelarkinn/refactor-flag-dep-p…
Browse files Browse the repository at this point in the history
…lugins

refactor(plugins): reduce memory footprint in string usages for multiple plugins
  • Loading branch information
TheLarkInn committed Mar 31, 2023
2 parents 6364822 + 4fda34a commit 92ccb9e
Show file tree
Hide file tree
Showing 4 changed files with 386 additions and 406 deletions.
49 changes: 22 additions & 27 deletions lib/FlagAllModulesAsUsedPlugin.js
Expand Up @@ -10,6 +10,7 @@ const { getEntryRuntime, mergeRuntimeOwned } = require("./util/runtime");
/** @typedef {import("./Compiler")} Compiler */
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */

const PLUGIN_NAME = "FlagAllModulesAsUsedPlugin";
class FlagAllModulesAsUsedPlugin {
constructor(explanation) {
this.explanation = explanation;
Expand All @@ -21,34 +22,28 @@ class FlagAllModulesAsUsedPlugin {
* @returns {void}
*/
apply(compiler) {
compiler.hooks.compilation.tap(
"FlagAllModulesAsUsedPlugin",
compilation => {
const moduleGraph = compilation.moduleGraph;
compilation.hooks.optimizeDependencies.tap(
"FlagAllModulesAsUsedPlugin",
modules => {
/** @type {RuntimeSpec} */
let runtime = undefined;
for (const [name, { options }] of compilation.entries) {
runtime = mergeRuntimeOwned(
runtime,
getEntryRuntime(compilation, name, options)
);
}
for (const module of modules) {
const exportsInfo = moduleGraph.getExportsInfo(module);
exportsInfo.setUsedInUnknownWay(runtime);
moduleGraph.addExtraReason(module, this.explanation);
if (module.factoryMeta === undefined) {
module.factoryMeta = {};
}
module.factoryMeta.sideEffectFree = false;
}
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
const moduleGraph = compilation.moduleGraph;
compilation.hooks.optimizeDependencies.tap(PLUGIN_NAME, modules => {
/** @type {RuntimeSpec} */
let runtime = undefined;
for (const [name, { options }] of compilation.entries) {
runtime = mergeRuntimeOwned(
runtime,
getEntryRuntime(compilation, name, options)
);
}
for (const module of modules) {
const exportsInfo = moduleGraph.getExportsInfo(module);
exportsInfo.setUsedInUnknownWay(runtime);
moduleGraph.addExtraReason(module, this.explanation);
if (module.factoryMeta === undefined) {
module.factoryMeta = {};
}
);
}
);
module.factoryMeta.sideEffectFree = false;
}
});
});
}
}

Expand Down

0 comments on commit 92ccb9e

Please sign in to comment.