Skip to content

Commit 8753c5a

Browse files
committed
doc: add performance warning to require.extensions
Discourage using require.extensions because it slows down the module loader. The number of file system operations that the module system has to perform in order to resolve a `require(...)` statement to a filename is proportional to the number of registered extensions.
1 parent b92556b commit 8753c5a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

doc/api/globals.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,17 @@ However, in practice, there are much better ways to do this, such as
216216
loading modules via some other Node.js program, or compiling them to
217217
JavaScript ahead of time.
218218

219-
Since the Module system is locked, this feature will probably never go
219+
Since the module system is locked, this feature will probably never go
220220
away. However, it may have subtle bugs and complexities that are best
221221
left untouched.
222222

223+
Note that the number of file system operations that the module system
224+
has to perform in order to resolve a `require(...)` statement to a
225+
filename scales linearly with the number of registered extensions.
226+
227+
In other words, adding extensions slows down the module loader and
228+
should be discouraged.
229+
223230
### require.resolve()
224231
<!-- YAML
225232
added: v0.3.0

0 commit comments

Comments
 (0)