Skip to content

fix(node:perf_hooks): measure/observe validation + eventLoopUtilization diffs#3517

Merged
proggeramlug merged 3 commits into
mainfrom
fix-perfhooks-3088-3008-3010-3011
May 31, 2026
Merged

fix(node:perf_hooks): measure/observe validation + eventLoopUtilization diffs#3517
proggeramlug merged 3 commits into
mainfrom
fix-perfhooks-3088-3008-3010-3011

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

Closes #3088
Closes #3008
Closes #3010
Closes #3011

Implementation

All changes are in the node:perf_hooks runtime (crates/perry-runtime/src/perf_hooks.rs) plus the two eventLoopUtilization call sites. No new HIR variants.

#3088performance.measure(name) string validation. measure previously string-coerced the name like mark. It now requires a real string (heap or SSO); every non-string (undefined, null, number, boolean, object, array, symbol) throws TypeError with Node's ERR_INVALID_ARG_TYPE message, including the Received ... suffix (undefined, null, type number (0), type boolean (true), an instance of Object, an instance of Array, type symbol (Symbol(s))). mark() name coercion is unchanged (mark(1).name === "1").

#3008 — User Timing option/timestamp validation.

  • mark({ startTime }): negative numeric value throws ERR_PERFORMANCE_INVALID_TIMESTAMP (-1 is not a valid timestamp); non-numeric throws the ERR_INVALID_ARG_TYPE startTime message with the received value.
  • measure(name, options): { start, end, duration } all present throws ERR_PERFORMANCE_MEASURE_INVALID_OPTIONS; negative numeric duration throws the invalid-timestamp error; a string start/end that doesn't name an existing mark now throws (SyntaxError: The "X" performance mark has not been set) instead of silently resolving to 0. Positional missing-mark resolution switched from TypeError to SyntaxError to match Node's err.name. Valid {start,end}/{start,duration}/{duration,end} still succeed.

#3010PerformanceObserver.observe() option validation. Non-object/non-undefined options throw ERR_INVALID_ARG_TYPE; neither entryTypes nor type specified throws ERR_MISSING_ARGS; both specified throws ERR_INVALID_ARG_VALUE; entryTypes present but not an array throws the must be string[] message. Lenient unknown-but-well-typed names (entryTypes: [], ["bogus"], type: "bogus") still succeed and observe nothing.

#3011 — two-argument eventLoopUtilization diffs. js_perf_event_loop_utilization now takes (util1, util2): zero-arg = cumulative, one-arg = current − util1, two-arg = util1 − util2. Updated the dynamic dispatch (native_module_dispatch.rs), static codegen (lower_call/native/perf_hooks.rs), and the FFI decl (runtime_decls/stdlib_ffi.rs) to pass/accept the second argument.

Validation

test-files/test_gap_perfhooks_3088_3008_3010_3011.ts is byte-identical to node --experimental-strip-types under the DEFAULT auto-optimize compile. The eventLoopUtilization assertions check object shape/keys (active,idle,utilization), value ranges, and types — never raw timestamps. Validation cases print err.name + ": " + err.message.

Guards: ./scripts/check_file_size.sh (OK), cargo fmt --all -- --check (clean), cargo test --release -p perry-runtime perf (2 pass), cargo test --release -p perry-hir (all pass). No new #[no_mangle] functions were added, so no keepalive anchors were needed.

@proggeramlug proggeramlug merged commit f058d82 into main May 31, 2026
@proggeramlug proggeramlug deleted the fix-perfhooks-3088-3008-3010-3011 branch May 31, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant