Skip to content

Commit c546871

Browse files
sokraevilebottnawi
authored andcommitted
perf: improvement for webpack@5 (#406)
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)
1 parent 5db376b commit c546871

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/index.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,20 @@ class CopyPlugin {
9898
compiler.hooks.afterEmit.tapAsync(plugin, (compilation, callback) => {
9999
logger.debug('starting after-emit');
100100

101-
// Add file dependencies if they're not already tracked
102-
for (const fileDependency of fileDependencies) {
103-
if (compilation.fileDependencies.has(fileDependency)) {
104-
logger.debug(
105-
`not adding '${fileDependency}' to change tracking, because it's already tracked`
106-
);
107-
} else {
108-
logger.debug(`adding '${fileDependency}' to change tracking`);
109-
101+
// Add file dependencies
102+
if ("addAll" in compilation.fileDependencies) {
103+
compilation.fileDependencies.addAll(fileDependencies);
104+
} else {
105+
for (const fileDependency of fileDependencies) {
110106
compilation.fileDependencies.add(fileDependency);
111107
}
112108
}
113109

114-
// Add context dependencies if they're not already tracked
115-
for (const contextDependency of contextDependencies) {
116-
if (compilation.contextDependencies.has(contextDependency)) {
117-
logger.debug(
118-
`not adding '${contextDependency}' to change tracking, because it's already tracked`
119-
);
120-
} else {
121-
logger.debug(`adding '${contextDependency}' to change tracking`);
122-
110+
// Add context dependencies
111+
if ("addAll" in compilation.contextDependencies) {
112+
compilation.contextDependencies.addAll(contextDependencies);
113+
} else {
114+
for (const contextDependency of contextDependencies) {
123115
compilation.contextDependencies.add(contextDependency);
124116
}
125117
}

0 commit comments

Comments
 (0)