Skip to content

Commit

Permalink
doc: add performance warning to require.extensions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bnoordhuis authored and evanlucas committed Nov 2, 2016
1 parent 60a5b51 commit ce00a9d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion doc/api/globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,17 @@ However, in practice, there are much better ways to do this, such as
loading modules via some other Node.js program, or compiling them to
JavaScript ahead of time.

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

Note that the number of file system operations that the module system
has to perform in order to resolve a `require(...)` statement to a
filename scales linearly with the number of registered extensions.

In other words, adding extensions slows down the module loader and
should be discouraged.

### require.resolve()
<!-- YAML
added: v0.3.0
Expand Down

0 comments on commit ce00a9d

Please sign in to comment.