Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatoli Papirovski <apapirovski@mac.com>2018-02-05 22:29:32 +0300
committerAnatoli Papirovski <apapirovski@mac.com>2018-02-09 22:59:07 +0300
commit0f9efef05deb11dbbdf5adf96460839f5b332207 (patch)
treea3e7fe462124de4f41f1dd21cb0a3267c864d1fa /src/timer_wrap.cc
parente5f101fe7beba032089ae3b3fb425c0ee15df258 (diff)
timers: refactor timer list processing
Instead of using kOnTimeout index to track a special list processing function, just pass in a function to C++ at startup that executes all handles and determines which function to call. This change improves the performance of unpooled timeouts by roughly 20%, as well as makes the unref/ref processing easier to follow. PR-URL: https://github.com/nodejs/node/pull/18582 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Vladimir de Turckheim <vlad2t@hotmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com>
Diffstat (limited to 'src/timer_wrap.cc')
-rw-r--r--src/timer_wrap.cc17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc
index 441974ae77b..02c0b816698 100644
--- a/src/timer_wrap.cc
+++ b/src/timer_wrap.cc
@@ -41,8 +41,6 @@ using v8::Object;
using v8::String;
using v8::Value;
-const uint32_t kOnTimeout = 0;
-
class TimerWrap : public HandleWrap {
public:
static void Initialize(Local<Object> target,
@@ -53,8 +51,6 @@ class TimerWrap : public HandleWrap {
Local<String> timerString = FIXED_ONE_BYTE_STRING(env->isolate(), "Timer");
constructor->InstanceTemplate()->SetInternalFieldCount(1);
constructor->SetClassName(timerString);
- constructor->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "kOnTimeout"),
- Integer::New(env->isolate(), kOnTimeout));
env->SetTemplateMethod(constructor, "now", Now);
@@ -71,18 +67,22 @@ class TimerWrap : public HandleWrap {
target->Set(timerString, constructor->GetFunction());
target->Set(env->context(),
- FIXED_ONE_BYTE_STRING(env->isolate(), "setImmediateCallback"),
- env->NewFunctionTemplate(SetImmediateCallback)
+ FIXED_ONE_BYTE_STRING(env->isolate(), "setupTimers"),
+ env->NewFunctionTemplate(SetupTimers)
->GetFunction(env->context()).ToLocalChecked()).FromJust();
}
size_t self_size() const override { return sizeof(*this); }
private:
- static void SetImmediateCallback(const FunctionCallbackInfo<Value>& args) {
+ static void SetupTimers(const FunctionCallbackInfo<Value>& args) {
CHECK(args[0]->IsFunction());
+ CHECK(args[1]->IsFunction());
auto env = Environment::GetCurrent(args);
+
env->set_immediate_callback_function(args[0].As<Function>());
+ env->set_timers_callback_function(args[1].As<Function>());
+
auto toggle_ref_cb = [] (const FunctionCallbackInfo<Value>& args) {
Environment::GetCurrent(args)->ToggleImmediateRef(args[0]->IsTrue());
};
@@ -142,7 +142,8 @@ class TimerWrap : public HandleWrap {
Local<Value> args[1];
do {
args[0] = env->GetNow();
- ret = wrap->MakeCallback(kOnTimeout, 1, args).ToLocalChecked();
+ ret = wrap->MakeCallback(env->timers_callback_function(), 1, args)
+ .ToLocalChecked();
} while (ret->IsUndefined() &&
!env->tick_info()->has_thrown() &&
wrap->object()->Get(env->context(),