简体   繁体   English

对Node.js中未使用的需求的性能影响?

[英]Performance impact on unused require in Node.js?

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? 我一直在想,当使用require()包含多个包并且不再使用它们时,Node.js中的性能是否有任何影响? I mean the situation when I, for example, require underscorejs and not touch it anymore: 我的意思是当我例如需要underscorejs并且不再触摸它时的情况:

var _ = require('underscore');

Doing so in C++ (unused includes) increases the compilation time. 在C ++中使用(未使用的包含)会增加编译时间。 But since in JavaScript there is no compilation, is this any harmful? 但是因为在JavaScript中没有编译,这有什么害处吗? Is the required module loaded when I run the file or only when I use any function from that module? 我运行文件时是否加载了所需的模块,或者仅当我使用该模块中的任何函数时?

An unused require will impact your application's startup performance a bit, as well as increase its memory footprint. 未使用的require会影响应用程序的启动性能,并增加其内存占用量。

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. 无论您是否稍后引用该模块,都会加载所需的模块,因此如果您实际上没有使用该模块,则需要删除它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM