Do unused ES6 modules affect performance?

僤鯓⒐⒋嵵緔 提交于 2019-12-12 19:20:36

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/47580376/do-unused-es6-modules-affect-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!