Skip to content

Commit

Permalink
fix low hanging performance problems with ProgressPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Jul 24, 2019
1 parent 04b0d6b commit fde3f62
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
1 change: 0 additions & 1 deletion lib/ProgressPlugin.js
Expand Up @@ -263,7 +263,6 @@ class ProgressPlugin {
recordModules: "record modules",
recordChunks: "record chunks",
beforeHash: "hashing",
contentHash: "content hashing",
afterHash: "after hashing",
recordHash: "record hash",
beforeModuleAssets: "module assets processing",
Expand Down
42 changes: 25 additions & 17 deletions lib/SourceMapDevToolPlugin.js
Expand Up @@ -49,27 +49,13 @@ const assetsCache = new WeakMap();
/**
* Creating {@link SourceMapTask} for given file
* @param {string} file current compiled file
* @param {Source} asset the asset
* @param {Chunk} chunk related chunk
* @param {SourceMapDevToolPluginOptions} options source map options
* @param {Compilation} compilation compilation instance
* @returns {SourceMapTask | undefined} created task instance or `undefined`
*/
const getTaskForFile = (file, chunk, options, compilation) => {
const asset = compilation.assets[file];
const cache = assetsCache.get(asset);
/**
* If presented in cache, reassigns assets. Cache assets already have source maps.
*/
if (cache && cache.file === file) {
for (const cachedFile in cache.assets) {
compilation.assets[cachedFile] = cache.assets[cachedFile];
/**
* Add file to chunk, if not presented there
*/
if (cachedFile !== file) chunk.files.push(cachedFile);
}
return;
}
const getTaskForFile = (file, asset, chunk, options, compilation) => {
let source, sourceMap;
/**
* Check if asset can build source map
Expand Down Expand Up @@ -189,13 +175,35 @@ class SourceMapDevToolPlugin {
reportProgress(0.0);
const tasks = [];
files.forEach(({ file, chunk }, idx) => {
const asset = compilation.assets[file];
const cache = assetsCache.get(asset);
/**
* If presented in cache, reassigns assets. Cache assets already have source maps.
*/
if (cache && cache.file === file) {
for (const cachedFile in cache.assets) {
compilation.assets[cachedFile] = cache.assets[cachedFile];
/**
* Add file to chunk, if not presented there
*/
if (cachedFile !== file) chunk.files.push(cachedFile);
}
return;
}

reportProgress(
(0.5 * idx) / files.length,
file,
"generate SourceMap"
);
/** @type {SourceMapTask | undefined} */
const task = getTaskForFile(file, chunk, options, compilation);
const task = getTaskForFile(
file,
asset,
chunk,
options,
compilation
);

if (task) {
const modules = task.sourceMap.sources.map(source => {
Expand Down

0 comments on commit fde3f62

Please sign in to comment.