Skip to content

Commit 8c33455

Browse files
committed
src: add fast loop idle time variation
``` perf_hooks/bench-eventlooputil.js method='ELU_passed' n=1000000 1.18 % ±2.02% ±2.69% ±3.50% perf_hooks/bench-eventlooputil.js method='ELU_simple' n=1000000 *** 7.29 % ±1.84% ±2.45% ±3.19% perf_hooks/bench-eventlooputil.js method='idleTime' n=1000000 ** 4.20 % ±2.97% ±3.96% ±5.15% ```
1 parent 8ac2901 commit 8c33455

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

benchmark/worker/bench-eventlooputil.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if (process.argv[2] === 'idle cats') {
88
}
99

1010
const bench = common.createBenchmark(main, {
11-
n: [1e6],
11+
n: [1e7],
1212
method: [
1313
'ELU_simple',
1414
'ELU_passed',

src/node_external_reference.h

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ using CFunctionCallbackReturnInt32 =
3838
v8::FastApiCallbackOptions& options);
3939
using CFunctionCallbackValueReturnDouble =
4040
double (*)(v8::Local<v8::Value> receiver);
41+
using CFunctionCallbackValueReturnDoubleOptions =
42+
double (*)(v8::Local<v8::Value>,
43+
// NOLINTNEXTLINE(runtime/references) This is V8 api.
44+
v8::FastApiCallbackOptions&);
4145
using CFunctionCallbackValueReturnDoubleUnusedReceiver =
4246
double (*)(v8::Local<v8::Value> unused, v8::Local<v8::Value> receiver);
4347
using CFunctionCallbackWithInt64 = void (*)(v8::Local<v8::Object> unused,
@@ -108,6 +112,7 @@ class ExternalReferenceRegistry {
108112
V(CFunctionCallbackReturnDouble) \
109113
V(CFunctionCallbackReturnInt32) \
110114
V(CFunctionCallbackValueReturnDouble) \
115+
V(CFunctionCallbackValueReturnDoubleOptions) \
111116
V(CFunctionCallbackValueReturnDoubleUnusedReceiver) \
112117
V(CFunctionCallbackWithInt64) \
113118
V(CFunctionCallbackWithBool) \

src/node_perf.cc

+14-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace performance {
1717
using v8::Array;
1818
using v8::Context;
1919
using v8::DontDelete;
20+
using v8::FastApiCallbackOptions;
2021
using v8::Function;
2122
using v8::FunctionCallbackInfo;
2223
using v8::GCCallbackFlags;
@@ -263,6 +264,15 @@ void LoopIdleTime(const FunctionCallbackInfo<Value>& args) {
263264
args.GetReturnValue().Set(1.0 * idle_time / NANOS_PER_MILLIS);
264265
}
265266

267+
static double FastLoopIdleTime(v8::Local<v8::Value> receiver,
268+
FastApiCallbackOptions& options) { // NOLINT(runtime/references)
269+
Environment* env = Environment::GetCurrent(options.isolate);
270+
uint64_t idle_time = uv_metrics_idle_time(env->event_loop());
271+
return 1.0 * idle_time / NANOS_PER_MILLIS;
272+
}
273+
274+
static v8::CFunction fast_loop_idle_time(v8::CFunction::Make(FastLoopIdleTime));
275+
266276
void UvMetricsInfo(const FunctionCallbackInfo<Value>& args) {
267277
Environment* env = Environment::GetCurrent(args);
268278
Isolate* isolate = env->isolate();
@@ -338,7 +348,8 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
338348
"removeGarbageCollectionTracking",
339349
RemoveGarbageCollectionTracking);
340350
SetMethod(isolate, target, "notify", Notify);
341-
SetMethod(isolate, target, "loopIdleTime", LoopIdleTime);
351+
SetFastMethodNoSideEffect(
352+
isolate, target, "loopIdleTime", LoopIdleTime, &fast_loop_idle_time);
342353
SetMethod(isolate, target, "createELDHistogram", CreateELDHistogram);
343354
SetMethod(isolate, target, "markBootstrapComplete", MarkBootstrapComplete);
344355
SetMethod(isolate, target, "uvMetricsInfo", UvMetricsInfo);
@@ -406,6 +417,8 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
406417
registry->Register(RemoveGarbageCollectionTracking);
407418
registry->Register(Notify);
408419
registry->Register(LoopIdleTime);
420+
registry->Register(FastLoopIdleTime);
421+
registry->Register(fast_loop_idle_time.GetTypeInfo());
409422
registry->Register(CreateELDHistogram);
410423
registry->Register(MarkBootstrapComplete);
411424
registry->Register(UvMetricsInfo);

0 commit comments

Comments
 (0)