Search code examples
javascriptmodulelodashes6-modules

Lodash: individual function import weighs more than importing whole library


Why individually importing lodash functions weigh more than loading the whole library at once (top line)?

enter image description here

The whole library cost 71.5k but individually importing some functions weigh around 162k. What's the reason?


Solution

  • There are a lot of mutual dependencies (mutual code that they all share) between those individual imports. The extension that you are using is most likely evaluating the weights of the imports with that mutual code for every single function separately. That ends up increasing the count for individual imports. Modern bundlers will ensure mutual code stays mutual; importing individual functions should still be more efficient.