Skip to content

Commit 15d05bb

Browse files
addaleaxMylesBorins
authored andcommitted
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: #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]>
1 parent 383d512 commit 15d05bb

File tree

1 file changed

+20
-39
lines changed

1 file changed

+20
-39
lines changed

src/node_perf.cc

+20-39
Original file line numberDiff line numberDiff line change
@@ -317,49 +317,30 @@ void TimerFunctionCall(const FunctionCallbackInfo<Value>& args) {
317317
size_t idx;
318318
SlicedArguments call_args(args);
319319
Utf8Value name(isolate, GetName(fn));
320+
bool is_construct_call = args.IsConstructCall();
320321

321-
uint64_t start;
322-
uint64_t end;
323-
v8::TryCatch try_catch(isolate);
324-
if (args.IsConstructCall()) {
325-
start = PERFORMANCE_NOW();
326-
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
327-
TRACING_CATEGORY_NODE2(perf, timerify),
328-
*name, *name, start / 1000);
329-
v8::MaybeLocal<Object> ret = fn->NewInstance(context,
330-
call_args.size(),
331-
call_args.data());
332-
end = PERFORMANCE_NOW();
333-
TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
334-
TRACING_CATEGORY_NODE2(perf, timerify),
335-
*name, *name, end / 1000);
336-
337-
if (ret.IsEmpty()) {
338-
try_catch.ReThrow();
339-
return;
340-
}
341-
args.GetReturnValue().Set(ret.ToLocalChecked());
322+
uint64_t start = PERFORMANCE_NOW();
323+
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
324+
TRACING_CATEGORY_NODE2(perf, timerify),
325+
*name, *name, start / 1000);
326+
v8::MaybeLocal<Value> ret;
327+
328+
if (is_construct_call) {
329+
ret = fn->NewInstance(context, call_args.size(), call_args.data())
330+
.FromMaybe(Local<Object>());
342331
} else {
343-
start = PERFORMANCE_NOW();
344-
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
345-
TRACING_CATEGORY_NODE2(perf, timerify),
346-
*name, *name, start / 1000);
347-
v8::MaybeLocal<Value> ret = fn->Call(context,
348-
args.This(),
349-
call_args.size(),
350-
call_args.data());
351-
end = PERFORMANCE_NOW();
352-
TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
353-
TRACING_CATEGORY_NODE2(perf, timerify),
354-
*name, *name, end / 1000);
355-
356-
if (ret.IsEmpty()) {
357-
try_catch.ReThrow();
358-
return;
359-
}
360-
args.GetReturnValue().Set(ret.ToLocalChecked());
332+
ret = fn->Call(context, args.This(), call_args.size(), call_args.data());
361333
}
362334

335+
uint64_t end = PERFORMANCE_NOW();
336+
TRACE_EVENT_COPY_NESTABLE_ASYNC_END_WITH_TIMESTAMP0(
337+
TRACING_CATEGORY_NODE2(perf, timerify),
338+
*name, *name, end / 1000);
339+
340+
if (ret.IsEmpty())
341+
return;
342+
args.GetReturnValue().Set(ret.ToLocalChecked());
343+
363344
AliasedBuffer<uint32_t, v8::Uint32Array>& observers =
364345
env->performance_state()->observers;
365346
if (!observers[NODE_PERFORMANCE_ENTRY_TYPE_FUNCTION])

0 commit comments

Comments
 (0)