-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: refactor some internal/* code #12644
Conversation
@@ -4,16 +4,17 @@ const Buffer = require('buffer').Buffer; | |||
const Writable = require('stream').Writable; | |||
const fs = require('fs'); | |||
const util = require('util'); | |||
const constants = process.binding('constants').fs; | |||
|
|||
const O_APPEND = constants.O_APPEND | 0; |
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.
Might want to check if the implicit coercion to a 32-bit value was intentional (e.g. performance related or the values were not originally numbers for some reason)?
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 explored that a bit a couldn't find anything specific. I could be wrong, but I think the switch was more defensive just in case.
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.
This also converts to an integer if it was a float, or some other type of number-ish.
@@ -2,71 +2,71 @@ | |||
|
|||
const Buffer = require('buffer').Buffer; | |||
|
|||
module.exports = BufferList; | |||
module.exports = class BufferList { |
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.
Did you benchmark this change?
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, negligible difference in master with 5.7. Notable improvement under TF-I ... tho I'd have to pull the numbers back up. It was a week or so ago when I ran it.
lib/internal/process/next_tick.js
Outdated
function setupNextTick() { | ||
const promises = require('internal/process/promises'); | ||
const errors = require('internal/errors'); | ||
const emitPendingUnhandledRejections = promises.setup(scheduleMicrotasks); | ||
const emitPendingUnhandledRejections = promises(scheduleMicrotasks); |
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 know the other 'setup' instances had the benefit of not having to be assigned to a variable first, but perhaps we should at least change the variable name here to something more straight-forward, like setupPromises
instead of just promises
?
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.
Works for me..
d2e492e
to
4b4dc16
Compare
lib/internal/bootstrap_node.js
Outdated
_process.setupKillAndExit(); | ||
_process.setupSignalHandlers(); | ||
if (global.__coverage__) | ||
NativeModule.require('internal/process/write-coverage').setup(); | ||
NativeModule.require('internal/process/write-coverage')(); |
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.
Note: I used this naming convention for consistency with the other setup functions.
IMO, it would be better to preserve it for clarity.
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.
these are already different from the other ones tho and we eliminate an extraneous property lookup. I'm not going to fight for it, but I don't see much value in keeping the separate setup()
functions.
@@ -130,3 +121,12 @@ function addBuiltinLibsToObject(object) { | |||
}); | |||
}); | |||
} | |||
|
|||
module.exports = exports = { |
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.
Remove exports
?
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.
That's my preference but in a separate issue @sam-github expressed a preference for these to retain the = exports
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.
Why? There is no point. Since you are already exposing the variable name to grab it this way exports
is defunct. (Edit: because You can just access the variable anyways)
If necessary, we can remove this in another PR entirely but idk why we'd add more here...
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 also agree that re-assigning exports
is unnecessary. *shrug*
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'm perfectly happy with removing it.
lib/internal/process.js
Outdated
@@ -267,3 +257,14 @@ function setupRawDebug() { | |||
rawDebug(format.apply(null, arguments)); | |||
}; | |||
} | |||
|
|||
module.exports = exports = { |
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.
ditto?
4b4dc16
to
cbbfb03
Compare
@Fishrock123 ... ok, I dropped the commit that altered the naming conventions on the process setup items. PTAL |
Replied to the comment about |
cbbfb03
to
d1a95a5
Compare
Updated to remove the |
lib/internal/module.js
Outdated
@@ -130,3 +121,12 @@ function addBuiltinLibsToObject(object) { | |||
}); | |||
}); | |||
} | |||
|
|||
module.exports = { |
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.
Actually, I just realized we do need exports
re-assigned here in this file because exports.requireDepth
is modified in this module and lib/module.js checks this value.
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.
heh... doh!
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.
that particular bit could likely be refactored but I'll just replace the = exports =
here for now
d1a95a5
to
0c9bd21
Compare
CI is green |
LGTM |
@Fishrock123 ... does this LGTY? |
Will land this by monday if there are no further objections |
PR-URL: #12644 Reviewed-By: Brian White <mscdex@mscdex.net>
PR-URL: #12644 Reviewed-By: Brian White <mscdex@mscdex.net>
PR-URL: #12644 Reviewed-By: Brian White <mscdex@mscdex.net>
PR-URL: #12644 Reviewed-By: Brian White <mscdex@mscdex.net>
PR-URL: #12644 Reviewed-By: Brian White <mscdex@mscdex.net>
PR-URL: nodejs#12644 Reviewed-By: Brian White <mscdex@mscdex.net>
PR-URL: nodejs#12644 Reviewed-By: Brian White <mscdex@mscdex.net>
PR-URL: nodejs#12644 Reviewed-By: Brian White <mscdex@mscdex.net>
PR-URL: nodejs#12644 Reviewed-By: Brian White <mscdex@mscdex.net>
PR-URL: nodejs#12644 Reviewed-By: Brian White <mscdex@mscdex.net>
Should this be backported to |
Updates to use current constructor for freelist, which was changed under pr #12644 Ref: #12644 PR-URL: #14627 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Updates to use current constructor for freelist, which was changed under pr #12644 Ref: #12644 PR-URL: #14627 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This one is a bit of a grab bag containing a number of small edits to a number of internal/* modules that I have been accumulating. They generally are around code cleanup or modernization
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
internal: process, module, streams, lib, fs, freelist