avoid allocation of meta info for dependencies when unused

This commit is contained in:
Tobias Koppers 2021-01-27 13:19:37 +01:00
parent 52abb681ff
commit 21c08d56ec
3 changed files with 13 additions and 1 deletions

View File

@ -655,6 +655,14 @@ class ModuleGraph {
return meta; return meta;
} }
/**
* @param {any} thing any thing
* @returns {Object} metadata
*/
getMetaIfExisting(thing) {
return this._metaMap.get(thing);
}
// TODO remove in webpack 6 // TODO remove in webpack 6
/** /**
* @param {Module} module the module * @param {Module} module the module

View File

@ -66,7 +66,10 @@ class HarmonyImportSpecifierDependency extends HarmonyImportDependency {
* @returns {string[]} the imported ids * @returns {string[]} the imported ids
*/ */
getIds(moduleGraph) { getIds(moduleGraph) {
return moduleGraph.getMeta(this)[idsSymbol] || this.ids; const meta = moduleGraph.getMetaIfExisting(this);
if (meta === undefined) return this.ids;
const ids = meta[idsSymbol];
return ids !== undefined ? ids : this.ids;
} }
/** /**

1
types.d.ts vendored
View File

@ -5713,6 +5713,7 @@ declare class ModuleGraph {
isAsync(module: Module): boolean; isAsync(module: Module): boolean;
setAsync(module: Module): void; setAsync(module: Module): void;
getMeta(thing?: any): Object; getMeta(thing?: any): Object;
getMetaIfExisting(thing?: any): Object;
static getModuleGraphForModule( static getModuleGraphForModule(
module: Module, module: Module,
deprecateMessage: string, deprecateMessage: string,