node: avoid automatic microtask runs#8472
Conversation
|
@vkurchatkin The additional tests are great. For posterity can you explain in a little more detail why not running microtasks automatically will help (e.g. the same number of |
|
@trevnorris in fact it's not about some real advantage, but Doing The Right Thing™. Since we are taking control of microtask queue, it makes sense to disable autorun and only run microtasks when necessary. If we just call In case we have nextTick callbacks microtasks will run (with autorun enabled):
The third one is totally unnecessary as microtask queue is guaranteed to be empty at this point. With autorun disabled we make first call manually and avoid the third call. There is a way to avoid the first one too: if (tick_info->length() == 0) {
env()->isolate()->RunMicrotasks();
if (tick_info->length() == 0) {
tick_info->set_index(0);
return ret;
}
}but I don't know if it's a good idea or not. |
|
I don't think there's a need to stack the if (tick_info->length() == 0) {
env()->isolate()->RunMicrotasks();
}
if (tick_info->length() == 0) {
tick_info->set_index(0);
return ret;
}And that seems a perfectly reasonable solution to me. |
|
On the side, it does seem there's some sort of bug in V8 wrt the microtask scheduler. When running the tests in debug mode I get the following: This happens before and after this patch. Running the same against V8 3.28 (#8476) they don't fail. |
|
Merged it in 8dc6be1, updating the commit log with our conversation and adding the extra check in Thanks for all your work on this. |
looks the same except in case when |
As discussed in #8325 we should take advantage of
Isolate::SetAutorunMicrotasks. This requires running microtasks manually prior to checkingtick_info->length()asprocess.nextTickcan be called inside of a microtask.This change helps to avoid unnecessary automatic microtask runs and should positively affect performance.
/cc @trevnorris