我一直在想,如果使用require()包含多个包并且不再使用它们,是否会对Node.js中的性能产生任何影响? 例如,我的意思是,当我需要使用underscorejs而不再触摸它时:
var _ = require('underscore');
这样做在C ++(未使用包括)会增加编译时间。 但是因为在JavaScript中没有编译,这是否有害? 当我运行该文件时,或仅在使用该模块的任何功能时,是否加载了所需的模块?
I have been wondering if is there any impact on performance in Node.js when including multiple packages using require() and not using them anymore? I mean the situation when I, for example, require underscorejs and not touch it anymore:
var _ = require('underscore');
Doing so in C++ (unused includes) increases the compilation time. But since in JavaScript there is no compilation, is this any harmful? Is the required module loaded when I run the file or only when I use any function from that module?
最满意答案
未使用的require会稍微影响应用程序的启动性能,并增加其内存占用量。
无论您稍后是否引用该模块,都会加载所需的模块,因此如果您未实际使用该模块,则需要删除该模块。
An unused require will impact your application's startup performance a bit, as well as increase its memory footprint.
The required module is loaded whether or not you later reference the module, so it's worth removing if you're not actually using the module.
更多推荐
发布评论