Skip to content

Commit ce00a9d

Browse files
bnoordhuisevanlucas
authored andcommitted
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. PR-URL: #9196 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 60a5b51 commit ce00a9d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

doc/api/globals.md

+8-1
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)