-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
module: optimize platform lookup and initPath #3582
Conversation
This caches the value of `process.platform`, and creates the `modulePaths` array in a way that is more efficient and easier to read and understand (left-to-right instead of right-to-left).
Without having looked at the changes, I just want to say that this churn in the module system makes me uncomfortable. It has the potential to break a lot of code. |
LGTM |
@@ -460,29 +461,23 @@ Module.runMain = function() { | |||
}; | |||
|
|||
Module._initPaths = function() { | |||
const isWindows = process.platform === 'win32'; | |||
modulePaths = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. modulePaths
is global to this module, and calling _initPaths
, resets its value.
Line 485 in 810cc05
modulePaths = paths; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use modulePaths.length = 0
.
That doesn't create a new object which has to be garbage collected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@meinklaus _initPaths
is called only once and modulePaths is undefined
at the beginning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at https://github.com/zertosh/node/blob/module-improv/lib/module.js#L41 I don't think it is undefined.
If _initPaths
is only called once there is no need to assign modulePaths
again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arr.length = 0
is magical and AFIAK it's not a convention that's used here
@nodejs/ctc |
cc @bmeck |
+1 on cache of Is the goal here otherwise to improve startup time? This does have some This affects tests that mutate NODE_PATH: Don't know the history of things that used the trick in these tests, but Also some modules (minimal usage but still): On Mon, Nov 2, 2015 at 10:41 AM, Jeremiah Senkpiel <notifications@github.com
|
-0.5 on rest* On Mon, Nov 2, 2015 at 10:56 AM, Bradley Meck bradley.meck@gmail.com
|
@bmeck, another goal of the changes in |
Not sure this is worth it anymore. Closing to reduce noise. |
This caches the value of
process.platform
in a style that is consistent with the fs, os and path modules. It also improvesModule._initPath
in both legibility and simplicity. Instead of creating themodulePaths
array from right-to-left viaconcat
s andunshift
s, its now built left-to-right withpush
s. Although it is a micro-optimization, the changes make it much easier to read and understand.