-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
lib: improve module loading performance #5172
Conversation
} | ||
return st; | ||
} | ||
function tryCreateBuffer(size, fd, isUserFd) { |
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.
some spacing between functions would be nice
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.
Done
cf164c5
to
dc56390
Compare
var i = start; | ||
for (; i < path.length; ++i) { | ||
const code = path.charCodeAt(i); | ||
if (code === 47/*/*/ || code === 92/*\*/) |
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.
can you quote and space these so it doesn't just look like weird comments?
if (code === 47 /* '/' */ || code === 92 /* '\' */)
or
if (code === 47 || code === 92) // '/' or '\'
I personally find the latter clearest
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 was mainly keeping things consistent with the path perf PR. I don't really have a strong preference either way, but I do think that having the literals next to the character codes is easier to scan.
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 have to agree with @rvagg that the current code comment is rather unreadable (makes my eyes spin ;)) And Rod's latter example is the nicest alternative imho too.
Pretty impressive work, I find the regex replacement with manual parsers the most confronting part of this and worry about its maintainability and approachability. Any idea what portion of the speedup is due to those bits? If the functions are a nearly direct translation of the regexes then maybe put the regex at the top in a comment to show what it's trying to do. |
I don't recall the actual numbers for each regexp removal, but they are a decent amount. The added path root extraction functions were mostly ripped from the new path changes and I thought about adding them as new path methods, but wasn't so sure about it. |
LGTM but I do agree with the concerns over maintainability. Hopefully that's not going to be too much of an issue tho given that this code is pretty stable. |
|
||
// For each path | ||
for (var i = 0, PL = paths.length; i < PL; i++) { | ||
for (var i = 0; i < paths.length; i++) { |
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.
Any reason to not use let here instead of var ?
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.
let apparently still has some optimization issues in V8. For hot code paths var is still preferred
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, what @jasnell said.
FWIW merging these changes with #3594 actually provides a much larger increase (since less time is spent doing path resolution): ~34% for the full path case and ~25% for the directory case. |
Cautiously putting a don't land on v4.x label on. Would want this to sit in a stable for a while before pulling back |
@ronkorving As soon as the |
@mscdex ... ping... where is this one at? |
sounds good! |
dc56390
to
f6067f3
Compare
I've rebased and removed the realpath changes in anticipation of #3594. |
Still LGTM if CI is green |
f6067f3
to
ae9783d
Compare
PR-URL: nodejs#5172 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit improves module loading performance by at least ~25-35% in the module-loader benchmarks. Some optimization strategies include: * Try-finally/try-catch isolation * Replacing regular expressions with manual parsing * Avoiding unnecessary string and array creation * Avoiding constant recompilation of anonymous functions and function definitions within functions PR-URL: nodejs#5172 Reviewed-By: James M Snell <jasnell@gmail.com>
ae9783d
to
ae18bbe
Compare
@mscdex did you use the merge button for this???? if so I'm glad to see it is working as expected |
@thealphanerd No, I didn't use the merge button. |
@mscdex never mind then... was thrown off by the merge message above. Thanks for the heads up |
Should we land this on v5.x? There are conflicts and I'm imagining we may not want to land something that touches module and may have regressions if we are not cutting another v5.x |
@thealphanerd Something else to keep in mind is that the jump you see in that graph is also including the realpath changes, so it's not just this PR. I would probably hold off on backporting to v5.x just to be safe for now. |
added |
PR-URL: #5172 Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #5172 Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #5172 Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #5172 Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #5172 Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: #5172 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit improves module loading performance by at least ~25-35% in the module-loader benchmarks. Some optimization strategies include: * Try-finally/try-catch isolation * Replacing regular expressions with manual parsing * Avoiding unnecessary string and array creation * Avoiding constant recompilation of anonymous functions and function definitions within functions PR-URL: #5172 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit improves module loading performance by at least ~25-35% in the module-loader benchmarks. Some optimization strategies include: * Try-finally/try-catch isolation * Replacing regular expressions with manual parsing * Avoiding unnecessary string and array creation * Avoiding constant recompilation of anonymous functions and function definitions within functions PR-URL: nodejs/node#5172 Reviewed-By: James M Snell <jasnell@gmail.com>
This commit improves module loading performance by at least ~17-23% in the module-loader benchmarks.
This improvement is on top of the module loading performance boost brought on by #5123. Both PRs combined bring a total of ~54% improvement in module loading.
Some optimization strategies include:
function definitions within functions