-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
timers: allow Immediates to be unrefed #18139
timers: allow Immediates to be unrefed #18139
Conversation
61b648a
to
3a3c628
Compare
added: REPLACEME | ||
--> | ||
|
||
When called, requests that the Node.js event loop *not* exit so long as the |
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 a hard time understanding this sentence. Could you re-write it with simpler grammar? 🙏
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 don't mind rewriting but the current version is basically copy & pasted from Timers. If I'm doing that, I would prefer to do both in the same PR — if you don't mind?
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 fine then!
Slightly refactor the immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Document the new `immediate.ref()` and `immediate.unref()` methods.
3a3c628
to
83ff89b
Compare
Some changes to the performance profile here and also accounting for a few more edge cases around I need to write a few more tests before this lands but not sure when I'll get around to them. CI: https://ci.nodejs.org/job/node-test-pull-request/12529/ |
src/env-inl.h
Outdated
@@ -538,16 +550,27 @@ inline void Environment::set_fs_stats_field_array(double* fields) { | |||
|
|||
void Environment::SetImmediate(native_immediate_callback cb, | |||
void* data, | |||
v8::Local<v8::Object> obj) { | |||
v8::Local<v8::Object> obj, | |||
bool ref) { |
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.
Rather than a bool
, I'd prefer an enum type argument 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 didn't want that argument to be used, to be honest (it was solely there to not have to replicate the code within SetUnrefImmediate
). Would something like this address the concern (with CreateImmediate
being private)? Or would you still prefer enum in this situation?
void Environment::CreateImmediate(native_immediate_callback cb,
void* data,
v8::Local<v8::Object> obj,
bool ref) {
native_immediate_callbacks_.push_back({
cb,
data,
std::unique_ptr<v8::Persistent<v8::Object>>(obj.IsEmpty() ?
nullptr : new v8::Persistent<v8::Object>(isolate_, obj)),
ref
});
immediate_info()->count_inc(1);
}
void Environment::SetImmediate(native_immediate_callback cb,
void* data,
v8::Local<v8::Object> obj) {
CreateImmediate(cb, data, obj, true);
if (immediate_info()->ref_count() == 0)
ToggleImmediateRef(true);
immediate_info()->ref_count_inc(1);
}
void Environment::SetUnrefImmediate(native_immediate_callback cb,
void* data,
v8::Local<v8::Object> obj) {
CreateImmediate(cb, data, obj, false);
}
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.
Since CreateImmediate()
is private, it's not a big deal. Just a preference.
Thanks everyone! Landed in c123467 |
Refactor Immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Document the new `immediate.ref()` and `immediate.unref()` methods. Add SetImmediateUnref on the C++ side. PR-URL: #18139 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
This does not land cleanly on v9.x-staging. Can you submit a backport PR? |
Backported in #18488 |
Refactor Immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Document the new `immediate.ref()` and `immediate.unref()` methods. Add SetImmediateUnref on the C++ side. PR-URL: nodejs#18139 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
Refactor Immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Document the new `immediate.ref()` and `immediate.unref()` methods. Add SetImmediateUnref on the C++ side. Backport-PR-URL: #19006 PR-URL: #18139 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
Refactor Immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Document the new `immediate.ref()` and `immediate.unref()` methods. Add SetImmediateUnref on the C++ side. Backport-PR-URL: #19006 PR-URL: #18139 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
Refactor Immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Document the new `immediate.ref()` and `immediate.unref()` methods. Add SetImmediateUnref on the C++ side. Backport-PR-URL: #19006 PR-URL: #18139 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
Notable Changes: * **libuv**: - Updated to libuv 1.19.2 (Colin Ihrig) [#18918](#18918) * **src**: - Add initial support for Node.js-specific post-mortem metadata (Matheus Marchini) [#14901](#14901) * **timers**: - The return value of `setImmediate()` now has `ref()` and `unref()` methods (Anatoli Papirovski) [#18139](#18139) * **util**: - It is now possible to get the name for a numerical platform-specific error code as a string (Joyee Cheung) [#18186](#18186)
Notable Changes: * **libuv**: - Updated to libuv 1.19.2 (Colin Ihrig) [#18918](#18918) * **src**: - Add initial support for Node.js-specific post-mortem metadata (Matheus Marchini) [#14901](#14901) * **timers**: - The return value of `setImmediate()` now has `ref()` and `unref()` methods (Anatoli Papirovski) [#18139](#18139) * **util**: - It is now possible to get the name for a numerical platform-specific error code as a string (Joyee Cheung) [#18186](#18186) PR-URL: #19040 Prepared-By: Anna Henningsen <[email protected]>
Notable Changes: * **libuv**: - Updated to libuv 1.19.2 (Colin Ihrig) [#18918](#18918) * **src**: - Add initial support for Node.js-specific post-mortem metadata (Matheus Marchini) [#14901](#14901) * **timers**: - The return value of `setImmediate()` now has `ref()` and `unref()` methods (Anatoli Papirovski) [#18139](#18139) * **util**: - It is now possible to get the name for a numerical platform-specific error code as a string (Joyee Cheung) [#18186](#18186) PR-URL: #19040 Prepared-By: Anna Henningsen <[email protected]>
Refactor Immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Document the new `immediate.ref()` and `immediate.unref()` methods. Add SetImmediateUnref on the C++ side. PR-URL: nodejs#18139 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
Refactor Immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Document the new `immediate.ref()` and `immediate.unref()` methods. Add SetImmediateUnref on the C++ side. Backport-PR-URL: #19265 PR-URL: #18139 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
Refactor Immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Document the new `immediate.ref()` and `immediate.unref()` methods. Add SetImmediateUnref on the C++ side. PR-URL: nodejs#18139 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]> Reviewed-By: James M Snell <[email protected]>
Notable Changes: * **libuv**: - Updated to libuv 1.19.2 (Colin Ihrig) [nodejs#18918](nodejs#18918) * **src**: - Add initial support for Node.js-specific post-mortem metadata (Matheus Marchini) [nodejs#14901](nodejs#14901) * **timers**: - The return value of `setImmediate()` now has `ref()` and `unref()` methods (Anatoli Papirovski) [nodejs#18139](nodejs#18139) * **util**: - It is now possible to get the name for a numerical platform-specific error code as a string (Joyee Cheung) [nodejs#18186](nodejs#18186) PR-URL: nodejs#19040 Prepared-By: Anna Henningsen <[email protected]>
Slightly refactor the Immediates handling to allow for them to be unrefed, similar to setTimeout, but without extra handles. Adds
immediate.ref()
andimmediate.unref()
.There's a roughly 5-10% performance regression on some of the immediate benchmarks, as well as a more substantial regression on
clearImmediate
. Both are a result of needing to track an extra property on the Immediate class. That said, since 9.0.0 got released we've seen the performance onsetImmediate
benchmarks grow by roughly 40-50%, so IMO we can afford this slight regression.CI: https://ci.nodejs.org/job/node-test-pull-request/12523/
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/96/
CitGM: https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/1202/
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
timers