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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With