mirror of https://github.com/webpack/webpack.git
optimize SideEffectsFlagPlugin performance
This commit is contained in:
parent
8445f06fa9
commit
e6113e9787
|
@ -15,7 +15,7 @@ class ModuleGraphConnection {
|
|||
* @param {Module} module the referenced module
|
||||
* @param {string=} explanation some extra detail
|
||||
* @param {boolean=} weak the reference is weak
|
||||
* @param {function(): boolean=} condition condition for the connection
|
||||
* @param {function(ModuleGraphConnection): boolean=} condition condition for the connection
|
||||
*/
|
||||
constructor(
|
||||
originModule,
|
||||
|
@ -33,7 +33,7 @@ class ModuleGraphConnection {
|
|||
this.weak = weak;
|
||||
this.conditional = !!condition;
|
||||
this._active = true;
|
||||
/** @type {function(): boolean} */
|
||||
/** @type {function(ModuleGraphConnection): boolean} */
|
||||
this.condition = condition;
|
||||
/** @type {Set<string>} */
|
||||
this.explanations = undefined;
|
||||
|
@ -44,13 +44,13 @@ class ModuleGraphConnection {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param {function(): boolean} condition condition for the connection
|
||||
* @param {function(ModuleGraphConnection): boolean} condition condition for the connection
|
||||
* @returns {void}
|
||||
*/
|
||||
addCondition(condition) {
|
||||
if (this.conditional) {
|
||||
const old = this.condition;
|
||||
this.condition = () => old() && condition();
|
||||
this.condition = c => old(c) && condition(c);
|
||||
} else if (this._active) {
|
||||
this.conditional = true;
|
||||
this.condition = condition;
|
||||
|
@ -75,7 +75,7 @@ class ModuleGraphConnection {
|
|||
|
||||
get active() {
|
||||
if (!this.conditional) return this._active;
|
||||
return this.condition();
|
||||
return this.condition(this);
|
||||
}
|
||||
|
||||
set active(value) {
|
||||
|
|
|
@ -23,6 +23,21 @@ class HarmonyImportSideEffectDependency extends HarmonyImportDependency {
|
|||
get type() {
|
||||
return "harmony side effect evaluation";
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {ModuleGraph} moduleGraph module graph
|
||||
* @returns {function(): boolean} function to determine if the connection is active
|
||||
*/
|
||||
getCondition(moduleGraph) {
|
||||
return connection => {
|
||||
const refModule = connection.resolvedModule;
|
||||
return (
|
||||
!refModule ||
|
||||
refModule.factoryMeta === undefined ||
|
||||
!refModule.factoryMeta.sideEffectFree
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
makeSerializable(
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
const glob2regexp = require("glob-to-regexp");
|
||||
const { STAGE_DEFAULT } = require("../OptimizationStages");
|
||||
const HarmonyExportImportedSpecifierDependency = require("../dependencies/HarmonyExportImportedSpecifierDependency");
|
||||
const HarmonyImportSideEffectDependency = require("../dependencies/HarmonyImportSideEffectDependency");
|
||||
const HarmonyImportSpecifierDependency = require("../dependencies/HarmonyImportSpecifierDependency");
|
||||
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
|
@ -104,12 +103,12 @@ class SideEffectsFlagPlugin {
|
|||
|
||||
// Capture reexports of sideEffectFree modules
|
||||
for (const module of modules) {
|
||||
for (const dep of module.dependencies) {
|
||||
if (dep instanceof HarmonyExportImportedSpecifierDependency) {
|
||||
if (
|
||||
module.factoryMeta !== undefined &&
|
||||
module.factoryMeta.sideEffectFree
|
||||
) {
|
||||
for (const dep of module.dependencies) {
|
||||
if (dep instanceof HarmonyExportImportedSpecifierDependency) {
|
||||
const mode = dep.getMode(moduleGraph, true);
|
||||
if (mode.type === "normal-reexport") {
|
||||
let map = reexportMaps.get(module);
|
||||
|
@ -127,18 +126,6 @@ class SideEffectsFlagPlugin {
|
|||
}
|
||||
}
|
||||
}
|
||||
} else if (dep instanceof HarmonyImportSideEffectDependency) {
|
||||
const connection = moduleGraph.getConnection(dep);
|
||||
if (connection) {
|
||||
const refModule = connection.resolvedModule;
|
||||
if (
|
||||
refModule &&
|
||||
refModule.factoryMeta !== undefined &&
|
||||
refModule.factoryMeta.sideEffectFree
|
||||
) {
|
||||
connection.active = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue