Skip to content

Commit

Permalink
src: simplify TimerFunctionCall() in node_perf.cc
Browse files Browse the repository at this point in the history
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: #23782
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Matheus Marchini <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
addaleax authored and MylesBorins committed Dec 26, 2018
1 parent 383d512 commit 15d05bb
Showing 1 changed file with 20 additions and 39 deletions.
59 changes: 20 additions & 39 deletions src/node_perf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,49 +317,30 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& 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<Object> 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<Value> ret;

if (is_construct_call) {
ret = fn->NewInstance(context, call_args.size(), call_args.data())
.FromMaybe(Local<Object>());
} else {
start = PERFORMANCE_NOW();
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
TRACING_CATEGORY_NODE2(perf, timerify),
*name, *name, start / 1000);
v8::MaybeLocal<Value> 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<uint32_t, v8::Uint32Array>& observers =
env->performance_state()->observers;
if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION])
Expand Down

0 comments on commit 15d05bb

Please sign in to comment.