Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
lib: improve module loading performance#5172
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
mscdex commented Feb 10, 2016
lib/fs.js Outdated
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 dc56390Comparelib/fs.js Outdated
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 /* '\' */)
orif (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.
rvagg commented Feb 10, 2016
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. |
mscdex commented Feb 10, 2016
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. |
jasnell commented Feb 10, 2016
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. |
lib/module.js Outdated
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.
mscdex commented Feb 19, 2016
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. |
jasnell commented Feb 19, 2016
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 commented Feb 27, 2016
mscdex commented Feb 27, 2016
@ronkorving As soon as the |
jasnell commented Mar 21, 2016
@mscdex ... ping... where is this one at? |
mscdex commented Mar 21, 2016
jasnell commented Mar 21, 2016
sounds good! |
mscdex commented Apr 7, 2016
I've rebased and removed the realpath changes in anticipation of #3594. |
jasnell commented Apr 7, 2016
Still LGTM if CI is green |
mscdex commented Apr 14, 2016
f6067f3 to ae9783dComparePR-URL: nodejs#5172 Reviewed-By: James M Snell <[email protected]>
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 <[email protected]>
ae9783d to ae18bbeCompareMylesBorins commented Apr 14, 2016
@mscdex did you use the merge button for this???? if so I'm glad to see it is working as expected |
mscdex commented Apr 14, 2016
@thealphanerd No, I didn't use the merge button. |
MylesBorins commented Apr 15, 2016
@mscdex never mind then... was thrown off by the merge message above. Thanks for the heads up |
mhdawson commented Apr 15, 2016
MylesBorins commented Apr 19, 2016
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 |
mscdex commented Apr 19, 2016
@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. |
MylesBorins commented Apr 19, 2016
added |
PR-URL: #5172 Reviewed-By: James M Snell <[email protected]>
PR-URL: #5172 Reviewed-By: James M Snell <[email protected]>
PR-URL: #5172 Reviewed-By: James M Snell <[email protected]>
PR-URL: #5172 Reviewed-By: James M Snell <[email protected]>
PR-URL: #5172 Reviewed-By: James M Snell <[email protected]>
PR-URL: #5172 Reviewed-By: James M Snell <[email protected]>
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 <[email protected]>
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 <[email protected]>

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