Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do unused ES6 modules affect performance?

I know for a fact that unused Java/.NET imports won't affect performance. But I also know that implementations of require() (used to?) simply pull and concatenate the entire required module/file at compile time, and that the import statement is sort of an evolution of that. Is it actually different? Will forgetting a very big unused ES6 module in the import list affect my app's performance?

like image 973
iuliu.net Avatar asked Oct 23 '25 05:10

iuliu.net


1 Answers

Yes, it will definitely affect performance, especially if you have non-exported code that does something non-trivial in the module or the module imports other modules. The first time you import a module it will be executed once (and only once). According to the spec:

http://www.ecma-international.org/ecma-262/6.0/#sec-abstract-module-records

Do nothing if this module has already been evaluated. Otherwise, transitively evaluate all module dependences of this module and then evaluate this module

like image 132
mr.freeze Avatar answered Oct 25 '25 18:10

mr.freeze