Skip to content

node:perf_hooks: support two-argument eventLoopUtilization diffs #3011

@andrewtdiz

Description

@andrewtdiz

Summary

Node performance.eventLoopUtilization(utilization1, utilization2) computes the delta between two prior readings. Perry's runtime helper and dispatch path only accept/pass the first argument, so the two-argument form is treated like the one-argument current - utilization1 form.

Node 25.9.0 behavior

const { performance } = require("node:perf_hooks");

const a = performance.eventLoopUtilization();
setTimeout(() => {
  const b = performance.eventLoopUtilization();
  const twoArg = performance.eventLoopUtilization(b, a);
  const oneArg = performance.eventLoopUtilization(b);
  console.log(twoArg); // roughly b - a
  console.log(oneArg); // roughly current - b, a different/smaller interval
}, 50);

Local Node v25.9.0 after the delay produced a two-argument result with about 51ms idle / 0.46ms active, while the one-argument eventLoopUtilization(b) result represented only the tiny interval after b was captured.

Perry source evidence

  • crates/perry-runtime/src/perf_hooks.rs::js_perf_event_loop_utilization(prev: f64) has a single prev parameter and only computes cumulative values or current - prev.
  • Dynamic dispatch in crates/perry-runtime/src/object/native_module_dispatch.rs calls js_perf_event_loop_utilization(arg(0)) and drops arg(1).
  • Static lowering in crates/perry-codegen/src/lower_call/native/perf_hooks.rs also lowers only argument 0 for eventLoopUtilization.

Expected

performance.eventLoopUtilization(utilization1, utilization2) should subtract utilization2 from utilization1, matching Node. The existing zero-arg cumulative form and one-arg current - previous form should keep working.

Duplicate checks

  • eventLoopUtilization two argument
  • perf_hooks eventLoopUtilization util1 util2

I did not find an existing issue for the two-argument eventLoopUtilization() overload.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions