Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update webpack-sources for performance problem in hashing #13828

Merged
merged 1 commit into from Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions declarations/WebpackOptions.d.ts
Expand Up @@ -2481,6 +2481,10 @@ export interface StatsOptions {
* Group modules by their type.
*/
groupModulesByType?: boolean;
/**
* Group reasons by their origin module.
*/
groupReasonsByOrigin?: boolean;
/**
* Add the hash of the compilation.
*/
Expand Down Expand Up @@ -2561,6 +2565,10 @@ export interface StatsOptions {
* Add information about the reasons why modules are included.
*/
reasons?: boolean;
/**
* Space to display reasons (groups will be collapsed to fit this space).
*/
reasonsSpace?: number;
/**
* Add information about assets that are related to other assets (like SourceMaps for assets).
*/
Expand Down
34 changes: 32 additions & 2 deletions lib/stats/DefaultStatsFactoryPlugin.js
Expand Up @@ -1182,11 +1182,14 @@ const SIMPLE_EXTRACTORS = {
type,
compilation: { moduleGraph }
} = context;
object.reasons = factory.create(
const groupsReasons = factory.create(
`${type.slice(0, -8)}.reasons`,
Array.from(moduleGraph.getIncomingConnections(module)),
context
);
const limited = spaceLimited(groupsReasons, options.reasonsSpace);
object.reasons = limited.children;
object.filteredReasons = limited.filteredChildren;
},
usedExports: (
object,
Expand Down Expand Up @@ -1764,6 +1767,16 @@ const moduleGroup = (children, modules) => {
};
};

const reasonGroup = (children, reasons) => {
let active = false;
for (const reason of children) {
active = active || reason.active;
}
return {
active
};
};

/** @type {Record<string, (groupConfigs: GroupConfig[], context: StatsFactoryContext, options: NormalizedStatsOptions) => void>} */
const ASSETS_GROUPERS = {
_: (groupConfigs, context, options) => {
Expand Down Expand Up @@ -2074,7 +2087,24 @@ const RESULT_GROUPERS = {
"compilation.modules": MODULES_GROUPERS("module"),
"chunk.modules": MODULES_GROUPERS("chunk"),
"chunk.rootModules": MODULES_GROUPERS("root-of-chunk"),
"module.modules": MODULES_GROUPERS("nested")
"module.modules": MODULES_GROUPERS("nested"),
"module.reasons": {
groupReasonsByOrigin: groupConfigs => {
groupConfigs.push({
getKeys: reason => {
return [reason.module];
},
createGroup: (key, children, reasons) => {
return {
type: "from origin",
module: key,
children,
...reasonGroup(children, reasons)
};
}
});
}
}
};

// remove a prefixed "!" that can be specified to reverse sort order
Expand Down
8 changes: 6 additions & 2 deletions lib/stats/DefaultStatsPresetPlugin.js
Expand Up @@ -50,6 +50,7 @@ const NAMED_PRESETS = {
modulesSpace: Infinity,
chunkModulesSpace: Infinity,
assetsSpace: Infinity,
reasonsSpace: Infinity,
children: true
},
detailed: {
Expand All @@ -72,8 +73,9 @@ const NAMED_PRESETS = {
logging: true,
runtimeModules: true,
exclude: false,
modulesSpace: Infinity,
assetsSpace: Infinity
modulesSpace: 1000,
assetsSpace: 1000,
reasonsSpace: 1000
},
minimal: {
all: false,
Expand Down Expand Up @@ -194,6 +196,8 @@ const DEFAULTS = {
depth: OFF_FOR_TO_STRING,
cachedAssets: OFF_FOR_TO_STRING,
reasons: OFF_FOR_TO_STRING,
reasonsSpace: (o, { forToString }) => (forToString ? 15 : Infinity),
groupReasonsByOrigin: ON_FOR_TO_STRING,
usedExports: OFF_FOR_TO_STRING,
providedExports: OFF_FOR_TO_STRING,
optimizationBailout: OFF_FOR_TO_STRING,
Expand Down
60 changes: 51 additions & 9 deletions lib/stats/DefaultStatsPrinterPlugin.js
Expand Up @@ -374,6 +374,10 @@ const SIMPLE_PRINTERS = {
"modules"
)}`
: undefined,
"module.filteredReasons": filteredReasons =>
filteredReasons > 0
? `${filteredReasons} ${plural(filteredReasons, "reason", "reasons")}`
: undefined,
"module.filteredChildren": filteredChildren =>
filteredChildren > 0
? `${filteredChildren} ${plural(filteredChildren, "module", "modules")}`
Expand All @@ -393,6 +397,10 @@ const SIMPLE_PRINTERS = {
"moduleReason.active": (active, { formatFlag }) =>
active ? undefined : formatFlag("inactive"),
"moduleReason.resolvedModule": (module, { magenta }) => magenta(module),
"moduleReason.filteredChildren": filteredChildren =>
filteredChildren > 0
? `${filteredChildren} ${plural(filteredChildren, "reason", "reasons")}`
: undefined,

"module.profile.total": (value, { formatTime }) => formatTime(value),
"module.profile.resolving": (value, { formatTime }) =>
Expand Down Expand Up @@ -590,6 +598,7 @@ const ITEM_NAMES = {
"module.modules[]": "module",
"module.children[]": "module",
"module.reasons[]": "moduleReason",
"moduleReason.children[]": "moduleReason",
"module.issuerPath[]": "moduleIssuer",
"chunk.origins[]": "chunkOrigin",
"chunk.modules[]": "module",
Expand Down Expand Up @@ -721,6 +730,7 @@ const PREFERRED_ORDERS = {
"usedExports",
"optimizationBailout",
"reasons",
"filteredReasons",
"issuerPath",
"profile",
"modules",
Expand All @@ -734,7 +744,9 @@ const PREFERRED_ORDERS = {
"module",
"resolvedModule",
"loc",
"explanation"
"explanation",
"children",
"filteredChildren"
],
"module.profile": [
"total",
Expand Down Expand Up @@ -1019,10 +1031,32 @@ const SIMPLE_ELEMENT_JOINERS = {
chunkGroupAsset: joinOneLine,
chunkGroupChildGroup: joinOneLine,
chunkGroupChild: joinOneLine,
// moduleReason: (items, { moduleReason }) => {
// let hasName = false;
// return joinOneLine(
// items.filter(item => {
// switch (item.element) {
// case "moduleId":
// if (moduleReason.moduleId === moduleReason.module && item.content)
// hasName = true;
// break;
// case "module":
// if (hasName) return false;
// break;
// case "resolvedModule":
// return (
// moduleReason.module !== moduleReason.resolvedModule &&
// item.content
// );
// }
// return true;
// })
// );
// },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sokra Forgot to remove?

moduleReason: (items, { moduleReason }) => {
let hasName = false;
return joinOneLine(
items.filter(item => {
return joinExplicitNewLine(
items.map(item => {
switch (item.element) {
case "moduleId":
if (moduleReason.moduleId === moduleReason.module && item.content)
Expand All @@ -1032,13 +1066,21 @@ const SIMPLE_ELEMENT_JOINERS = {
if (hasName) return false;
break;
case "resolvedModule":
return (
moduleReason.module !== moduleReason.resolvedModule &&
item.content
);
if (moduleReason.module === moduleReason.resolvedModule)
return false;
break;
case "children":
if (item.content) {
return {
...item,
content: `\n${item.content}\n`
};
}
break;
}
return true;
})
return item;
}),
" "
);
},
"module.profile": joinInBrackets,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -27,7 +27,7 @@
"tapable": "^2.1.1",
"terser-webpack-plugin": "^5.1.3",
"watchpack": "^2.2.0",
"webpack-sources": "^2.3.0"
"webpack-sources": "^2.3.1"
},
"peerDependenciesMeta": {
"webpack-cli": {
Expand Down
2 changes: 1 addition & 1 deletion schemas/WebpackOptions.check.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions schemas/WebpackOptions.json
Expand Up @@ -4210,6 +4210,10 @@
"description": "Group modules by their type.",
"type": "boolean"
},
"groupReasonsByOrigin": {
"description": "Group reasons by their origin module.",
"type": "boolean"
},
"hash": {
"description": "Add the hash of the compilation.",
"type": "boolean"
Expand Down Expand Up @@ -4314,6 +4318,10 @@
"description": "Add information about the reasons why modules are included.",
"type": "boolean"
},
"reasonsSpace": {
"description": "Space to display reasons (groups will be collapsed to fit this space).",
"type": "number"
},
"relatedAssets": {
"description": "Add information about assets that are related to other assets (like SourceMaps for assets).",
"type": "boolean"
Expand Down
3 changes: 2 additions & 1 deletion test/TestCases.template.js
Expand Up @@ -252,7 +252,8 @@ const describeCases = config => {
const statOptions = {
preset: "verbose",
colors: false,
modules: true
modules: true,
reasonsSpace: 1000
};
fs.mkdirSync(outputDirectory, { recursive: true });
fs.writeFileSync(
Expand Down
26 changes: 26 additions & 0 deletions test/__snapshots__/Cli.test.js.snap
Expand Up @@ -7753,6 +7753,19 @@ Object {
"multiple": false,
"simpleType": "boolean",
},
"stats-group-reasons-by-origin": Object {
"configs": Array [
Object {
"description": "Group reasons by their origin module.",
"multiple": false,
"path": "stats.groupReasonsByOrigin",
"type": "boolean",
},
],
"description": "Group reasons by their origin module.",
"multiple": false,
"simpleType": "boolean",
},
"stats-hash": Object {
"configs": Array [
Object {
Expand Down Expand Up @@ -8058,6 +8071,19 @@ Object {
"multiple": false,
"simpleType": "boolean",
},
"stats-reasons-space": Object {
"configs": Array [
Object {
"description": "Space to display reasons (groups will be collapsed to fit this space).",
"multiple": false,
"path": "stats.reasonsSpace",
"type": "number",
},
],
"description": "Space to display reasons (groups will be collapsed to fit this space).",
"multiple": false,
"simpleType": "number",
},
"stats-related-assets": Object {
"configs": Array [
Object {
Expand Down