From ce00a9d2b6c4fe618d65508943412fcc492c3ce5 Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Wed, 19 Oct 2016 15:38:30 +0200 Subject: [PATCH] doc: add performance warning to require.extensions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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: https://github.com/nodejs/node/pull/9196 Reviewed-By: Brian White Reviewed-By: Colin Ihrig Reviewed-By: Evan Lucas Reviewed-By: Michaƫl Zasso Reviewed-By: James M Snell --- doc/api/globals.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/api/globals.md b/doc/api/globals.md index 32acc983ffdd2e..885e2e09fc8879 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -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()