未使用的ES6模块会影响性能吗? [英] Do unused ES6 modules affect performance?
问题描述
我知道未使用的Java / .NET导入不会影响性能。
但是我也知道的实现require()
(用于?)只是在编译时拉取并连接整个所需的模块/文件,而 import
语句是一种演变。它真的不一样吗?忘记导入列表中一个非常大的未使用的ES6模块会影响我的应用程序的性能吗?
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?
推荐答案
是的,它肯定会影响性能,特别是如果您有非导出的代码在模块中执行非常重要的操作或模块导入其他模块。第一次导入模块时,它将执行一次(并且只执行一次)。根据规范:
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
这篇关于未使用的ES6模块会影响性能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!