Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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? 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?

like image 738
kmachnicki Avatar asked Dec 25 '22 10:12

kmachnicki


1 Answers

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.

like image 136
JohnnyHK Avatar answered Jan 10 '23 02:01

JohnnyHK