From 15d05bbf0211277e85e78ea04c4e736f226d12f2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 20 Oct 2018 12:13:40 +0200 Subject: [PATCH] src: simplify `TimerFunctionCall()` in `node_perf.cc` Picking a path according to a boolean is essentially free, compared to the cost of a function call. Also, remove an unnecessary `TryCatch`. PR-URL: https://github.com/nodejs/node/pull/23782 Reviewed-By: Refael Ackermann Reviewed-By: Colin Ihrig Reviewed-By: Joyee Cheung Reviewed-By: Matheus Marchini Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- src/node_perf.cc | 59 ++++++++++++++++-------------------------------- 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/src/node_perf.cc b/src/node_perf.cc index aed97d2b3b263a..4aa5da03d7a7e4 100644 --- a/src/node_perf.cc +++ b/src/node_perf.cc @@ -317,49 +317,30 @@ void TimerFunctionCall(const FunctionCallbackInfo& args) { size_t idx; SlicedArguments call_args(args); Utf8Value name(isolate, GetName(fn)); + bool is_construct_call = args.IsConstructCall(); - uint64_t start; - uint64_t end; - v8::TryCatch try_catch(isolate); - if (args.IsConstructCall()) { - start = PERFORMANCE_NOW(); - TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0( - TRACING_CATEGORY_NODE2(perf, timerify), - *name, *name, start / 1000); - v8::MaybeLocal ret = fn->NewInstance(context, - call_args.size(), - call_args.data()); - end = PERFORMANCE_NOW(); - TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0( - TRACING_CATEGORY_NODE2(perf, timerify), - *name, *name, end / 1000); - - if (ret.IsEmpty()) { - try_catch.ReThrow(); - return; - } - args.GetReturnValue().Set(ret.ToLocalChecked()); + uint64_t start = PERFORMANCE_NOW(); + TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0( + TRACING_CATEGORY_NODE2(perf, timerify), + *name, *name, start / 1000); + v8::MaybeLocal ret; + + if (is_construct_call) { + ret = fn->NewInstance(context, call_args.size(), call_args.data()) + .FromMaybe(Local()); } else { - start = PERFORMANCE_NOW(); - TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0( - TRACING_CATEGORY_NODE2(perf, timerify), - *name, *name, start / 1000); - v8::MaybeLocal ret = fn->Call(context, - args.This(), - call_args.size(), - call_args.data()); - end = PERFORMANCE_NOW(); - TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0( - TRACING_CATEGORY_NODE2(perf, timerify), - *name, *name, end / 1000); - - if (ret.IsEmpty()) { - try_catch.ReThrow(); - return; - } - args.GetReturnValue().Set(ret.ToLocalChecked()); + ret = fn->Call(context, args.This(), call_args.size(), call_args.data()); } + uint64_t end = PERFORMANCE_NOW(); + TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0( + TRACING_CATEGORY_NODE2(perf, timerify), + *name, *name, end / 1000); + + if (ret.IsEmpty()) + return; + args.GetReturnValue().Set(ret.ToLocalChecked()); + AliasedBuffer& observers = env->performance_state()->observers; if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION])