Skip to content

perf_hooks: implement performance.eventLoopUtilization() - #32618

Closed
robobun wants to merge 9 commits into
mainfrom
farm/4b495614/worker-threads-elu
Closed

robobun wants to merge 9 commits into
mainfrom
farm/4b495614/worker-threads-elu

perf_hooks: implement performance.eventLoopUtilization()

7fa9cb8
Select commit
Loading
Failed to load commit list.
Claude / Claude Code Review completed Jul 16, 2026 in 24m 45s

Code review found 3 potential issues

Found 4 candidates, confirmed 3. See review comments for details.

Details

Severity Count
🔴 Important 0
🟡 Nit 3
🟣 Pre-existing 0
Severity File:Line Issue
🟡 Nit src/jsc/bindings/webcore/Worker.cpp:393-399 worker.performance.eventLoopUtilization() returns non-zero before 'online' (Node returns zeros)
🟡 Nit src/jsc/bindings/webcore/JSWorker.cpp:451 eventLoopUtilization is enumerable internal plumbing on globalThis.Worker.prototype
🟡 Nit packages/bun-usockets/src/loop.c:33-41 us_loop_monotonic_ns duplicates pre-existing us_internal_monotonic_ns on POSIX

Annotations

Check warning on line 399 in src/jsc/bindings/webcore/Worker.cpp

See this annotation in the file changed.

@claude claude / Claude Code Review

worker.performance.eventLoopUtilization() returns non-zero before 'online' (Node returns zeros)

nit: Node's `worker.performance.eventLoopUtilization()` gates on `!this[kIsOnline]` and returns zeros until 'online' fires; this gate only checks `m_state >= Closing`, so during the window after `start_vm()` publishes `vm`+`uws_loop_ptr` but before `spin()` finishes loading the entry point and calls `WebWorker__dispatchOnline`, the parent gets `{idle:~0, active:<entry-load ms>}` where Node returns zeros. The JS-side `raw.idle===0 && raw.active===0` sentinel (whose comment claims to cover "not ye

Check warning on line 451 in src/jsc/bindings/webcore/JSWorker.cpp

See this annotation in the file changed.

@claude claude / Claude Code Review

eventLoopUtilization is enumerable internal plumbing on globalThis.Worker.prototype

nit: this entry is registered with `PropertyAttribute::Function` only (no `DontEnum`), so an internal-plumbing `eventLoopUtilization` method — which returns raw `{idle, active}` (no `utilization`) and exists solely for `worker_threads.ts` to call `this.#worker.eventLoopUtilization()` — becomes enumerable on `globalThis.Worker.prototype`. The file's own convention for such plumbing is `*Internal` + `DontEnum` (see the three entries immediately above, lines 448-450, and the existing test "*Interna

Check warning on line 41 in packages/bun-usockets/src/loop.c

See this annotation in the file changed.

@claude claude / Claude Code Review

us_loop_monotonic_ns duplicates pre-existing us_internal_monotonic_ns on POSIX

nit: The POSIX branch of the new `us_loop_monotonic_ns()` is byte-identical to the pre-existing `us_internal_monotonic_ns()` (loop.c:117-121, inside the `#else /* !LIBUS_USE_LIBUV */` block). Since the new function is a strict superset (also handles libuv via `uv_hrtime()`) and is already declared in internal.h, per CLAUDE.md ("If your fix makes two functions byte-identical, delete one") the pre-existing helper and its declaration at internal.h:160 could be dropped and its ~4 call sites (loop.c: