Description
Bug report
When an application contains a large number of assets and uses optimization.realContentHash
, the RealContentHashPlugin takes a very long time on the first asset that it processes for hash renaming. On a build with ~3200 assets, this results in approximately 40s spent in RealContentHashPlugin
which is almost entirely on the first invocation of the use of an expensive regular expression.
What is the current behavior?
Here's a CPU profile showing time spent in RealContentHashPlugin during a build:
Our application/config contains private code, so i can't share the complete results, but I've traced it to the regular expression that's generated from the asset keys in RealContentHashPlugin
. For an application like ours with ~3200 assets, this results in a regular expression that is the combination of each of those asset names joined by |
to form a group.
Instantiating this regular expression is inexpensive, but the first time it is invoked in takes ~40s to compile the underlying expression. The evaluation is then very fast, but the first invocation delays the entire process.
If the current behavior is a bug, please provide the steps to reproduce.
Reproduction repo: https://github.com/ryanwilsonperkin/webpack-16758
What is the expected behavior?
RealContentHashPlugin should avoid using a large group in this case, and instead should use individual regular expressions to match/replace each of the assets in a loop. Profiling this yielded a reduction from 41.87s to 0.006s
.
Other relevant information:
webpack version: 5.74.0
Node.js version: v16.18.1
Operating System: macOS 13.2
Additional tools:
Metadata
Metadata
Assignees
Type
Projects
Status