How expensive are multiple requires on the same file on the same instance of Node JS?
up vote
0
down vote
favorite
My understanding of require (so far) is that it performs a traversal up the directory structure, looking for the module you're trying to import. Well, that's not exactly correct, but let's assume the directory traversal cost is negligible.
I have a module called BigModule
. It has a lot of stuff in it, so there's some cost associated with loading it up with a require
statement. Is importing it a hundred times a hundred times more expensive than importing it once, or is there some sort of caching mechanism which causes these scripts to share one BigModule
instance? This is all happening on a single Node instance.
javascript typescript plugins
add a comment |
up vote
0
down vote
favorite
My understanding of require (so far) is that it performs a traversal up the directory structure, looking for the module you're trying to import. Well, that's not exactly correct, but let's assume the directory traversal cost is negligible.
I have a module called BigModule
. It has a lot of stuff in it, so there's some cost associated with loading it up with a require
statement. Is importing it a hundred times a hundred times more expensive than importing it once, or is there some sort of caching mechanism which causes these scripts to share one BigModule
instance? This is all happening on a single Node instance.
javascript typescript plugins
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
My understanding of require (so far) is that it performs a traversal up the directory structure, looking for the module you're trying to import. Well, that's not exactly correct, but let's assume the directory traversal cost is negligible.
I have a module called BigModule
. It has a lot of stuff in it, so there's some cost associated with loading it up with a require
statement. Is importing it a hundred times a hundred times more expensive than importing it once, or is there some sort of caching mechanism which causes these scripts to share one BigModule
instance? This is all happening on a single Node instance.
javascript typescript plugins
My understanding of require (so far) is that it performs a traversal up the directory structure, looking for the module you're trying to import. Well, that's not exactly correct, but let's assume the directory traversal cost is negligible.
I have a module called BigModule
. It has a lot of stuff in it, so there's some cost associated with loading it up with a require
statement. Is importing it a hundred times a hundred times more expensive than importing it once, or is there some sort of caching mechanism which causes these scripts to share one BigModule
instance? This is all happening on a single Node instance.
javascript typescript plugins
javascript typescript plugins
asked Nov 12 at 18:43
Brent Allard
104211
104211
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
require()
caches calls by resolved filepath; require()
ing the same file twice (even via symlink or different relative path) will not rerun the code.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
require()
caches calls by resolved filepath; require()
ing the same file twice (even via symlink or different relative path) will not rerun the code.
add a comment |
up vote
1
down vote
accepted
require()
caches calls by resolved filepath; require()
ing the same file twice (even via symlink or different relative path) will not rerun the code.
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
require()
caches calls by resolved filepath; require()
ing the same file twice (even via symlink or different relative path) will not rerun the code.
require()
caches calls by resolved filepath; require()
ing the same file twice (even via symlink or different relative path) will not rerun the code.
answered Nov 12 at 18:44
SLaks
671k13816111736
671k13816111736
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53268251%2fhow-expensive-are-multiple-requires-on-the-same-file-on-the-same-instance-of-nod%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown