diff options
author | Anatoli Papirovski <apapirovski@mac.com> | 2018-01-31 18:34:31 +0300 |
---|---|---|
committer | Anatoli Papirovski <apapirovski@mac.com> | 2018-02-04 19:04:12 +0300 |
commit | a986158cbf931da9d62eed0c921c105e29b76eda (patch) | |
tree | ed37a135dfe451659e6d838224cde9bc134ad5ae /src/timer_wrap.cc | |
parent | 9b8e1c2e4f0a4254b295316b10136a28cc36db4c (diff) |
timers: re-enter C++ less frequently
Pass in Timer.now() as an argument of kOnTimeout instead of always
re-entering C++ to get it. Also don't constantly call Timer.now()
from ontimeout, even when it isn't needed. Improves performance
on our pooled benchmark by upwards of 40%.
PR-URL: https://github.com/nodejs/node/pull/18486
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Diffstat (limited to 'src/timer_wrap.cc')
-rw-r--r-- | src/timer_wrap.cc | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/timer_wrap.cc b/src/timer_wrap.cc index 8b596eb4352..f1b423d3669 100644 --- a/src/timer_wrap.cc +++ b/src/timer_wrap.cc @@ -37,6 +37,7 @@ using v8::FunctionTemplate; using v8::HandleScope; using v8::Integer; using v8::Local; +using v8::Number; using v8::Object; using v8::String; using v8::Value; @@ -139,8 +140,10 @@ class TimerWrap : public HandleWrap { HandleScope handle_scope(env->isolate()); Context::Scope context_scope(env->context()); Local<Value> ret; + Local<Value> args[1]; do { - ret = wrap->MakeCallback(kOnTimeout, 0, nullptr).ToLocalChecked(); + args[0] = GetNow(env); + ret = wrap->MakeCallback(kOnTimeout, 1, args).ToLocalChecked(); } while (ret->IsUndefined() && !env->tick_info()->has_thrown() && wrap->object()->Get(env->context(), @@ -150,14 +153,18 @@ class TimerWrap : public HandleWrap { static void Now(const FunctionCallbackInfo<Value>& args) { Environment* env = Environment::GetCurrent(args); + args.GetReturnValue().Set(GetNow(env)); + } + + static Local<Value> GetNow(Environment* env) { uv_update_time(env->event_loop()); uint64_t now = uv_now(env->event_loop()); CHECK(now >= env->timer_base()); now -= env->timer_base(); if (now <= 0xfffffff) - args.GetReturnValue().Set(static_cast<uint32_t>(now)); + return Integer::New(env->isolate(), static_cast<uint32_t>(now)); else - args.GetReturnValue().Set(static_cast<double>(now)); + return Number::New(env->isolate(), static_cast<double>(now)); } uv_timer_t handle_; |