Skip to content

Commit

Permalink
perf: improvement for webpack@5 (#406)
Browse files Browse the repository at this point in the history
Sets don't allow duplicates, so checking for `has` is not necessary

webpack 5 makes these Sets lazy, which makes reading more expensive.
So only the watcher should read from these Sets, which is called after the compilation has finished,
so that doesn't contribute to build performance.

LazySets also have a `addAll` method, which allows to add an Iterable lazily (only iterated when LazySet is read)
  • Loading branch information
sokra authored and evilebottnawi committed Nov 5, 2019
1 parent 5db376b commit c546871
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions src/index.js
Expand Up @@ -98,28 +98,20 @@ class CopyPlugin {
compiler.hooks.afterEmit.tapAsync(plugin, (compilation, callback) => {
logger.debug('starting after-emit');

// Add file dependencies if they're not already tracked
for (const fileDependency of fileDependencies) {
if (compilation.fileDependencies.has(fileDependency)) {
logger.debug(
`not adding '${fileDependency}' to change tracking, because it's already tracked`
);
} else {
logger.debug(`adding '${fileDependency}' to change tracking`);

// Add file dependencies
if ("addAll" in compilation.fileDependencies) {
compilation.fileDependencies.addAll(fileDependencies);
} else {
for (const fileDependency of fileDependencies) {
compilation.fileDependencies.add(fileDependency);
}
}

// Add context dependencies if they're not already tracked
for (const contextDependency of contextDependencies) {
if (compilation.contextDependencies.has(contextDependency)) {
logger.debug(
`not adding '${contextDependency}' to change tracking, because it's already tracked`
);
} else {
logger.debug(`adding '${contextDependency}' to change tracking`);

// Add context dependencies
if ("addAll" in compilation.contextDependencies) {
compilation.contextDependencies.addAll(contextDependencies);
} else {
for (const contextDependency of contextDependencies) {
compilation.contextDependencies.add(contextDependency);
}
}
Expand Down

0 comments on commit c546871

Please sign in to comment.