Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`.
  • Loading branch information
addaleax committed Oct 20, 2018
commit 10eeec8dc9d22355303faef66d93250824b565c3
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) {
Comment thread
refack marked this conversation as resolved.
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())
Comment thread
refack marked this conversation as resolved.
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