Chunk.modules and Module.chunks should be javascript Set or Map

Do you want to request a feature or report a bug?
What is the current behavior?
The fact that Chunk.modules and Module.chunks are arrays is a performance issue, especially on the incremental builds when you have chunks that contain a lot of modules which happens a lot with legacy code…
Searching for a module in a list is O(n) for example and splicing the array is expensive memory-wise.

If the current behavior is a bug, please provide the steps to reproduce.

For it to be a significant problem you need a build with like 4-5000 modules that fall into the same chunk. I know this is not healthy, but it’s what some of us have to work with due to legacy until things get refactored, which might take a long time.

What is the expected behavior?
Chunk add/removeModule, Module add/removeChunk APIs are fast and use memory responsibly.

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
tried with nodejs 4.x/6.x and webpack 1.x, but in webpack 2, the data structures used did not change.

Here’s an example from a profiled incremental build. Chunk.removeModule has an “aggregated total time” of 1.78s. I think if we add all the usage of the API up, it could make up quite a chunk of the time for the incremental build, so making this change will bring improvements across the board…

The advantage of going with Set for the data structure is that it would be more similar to an array in terms of iteration, etc. Using Map would be nice since you could have the module/chunk id be the key…
The only issue that I see is that this could break some plugins which assume that those structures are arrays… unless maybe we can use an ES6 getter to return an array?

Author: Fantashit

1 thought on “Chunk.modules and Module.chunks should be javascript Set or Map

Comments are closed.