Repository navigation
perf: don't interrupt the uv loop for I/O changes made inside uv_run() - #52905
Merged
Conversation
Electron configures Node's libuv loop with UV_LOOP_INTERRUPT_ON_IO_CHANGE so that starting a timer/handle/watcher from a Chromium task wakes the embed thread, which may be blocked polling the backend fd with a stale timeout. The interrupt also fired for changes made while uv_run() itself was executing (e.g. Node toggling its immediate idle handle or timer handle on most ticks inside UvRunOnce), where nobody is polling: each of those cost a write()/kevent()/PostQueuedCompletionStatus on the main thread and made the embed thread's next poll return immediately, scheduling an extra empty UvRunOnce task per tick. Track uv_run() nesting in the loop's private internal fields and skip the I/O-change interrupt while it is non-zero. Once uv_run() returns the embedder re-reads uv_backend_timeout(), which already accounts for the change. uv_async_send() is unaffected. On Linux an idle app with a 10 ms setInterval goes from ~94 eventfd writes/s on the main thread and two UI-thread wakeups per tick to zero writes and one wakeup per tick, with identical timer/immediate ordering and latency. Also repairs the patch's test-embed.c (it no longer compiled against the current MAKE_VALGRIND_HAPPY signature) and adds a case that starts a timer from inside uv_run(UV_RUN_NOWAIT), asserting the external poller still fires it on time and, on Linux, that no interrupt was written. Co-authored-by: Shelley Vohr <[email protected]>
libuv/libuv#3308 is closed, so the sentence suggesting the gated variant be proposed there no longer applies. Description-only change. No-Verification-Needed: patch description text only Co-authored-by: Shelley Vohr <[email protected]>
…nside uv_run() Keying the gate on "uv_run() is on the stack" also covered a foreign nested uv_run() issued from a Chromium task (a native module pumping the loop), where the embed thread is polling with a stale timeout and does need the wakeup. Replace the in_run counter with an embedder-controlled uv_loop_interrupt_suspend()/resume() depth and wrap only UvRunOnce's uv_run() in it, since that is where the embed thread is known to be parked on embed_sem_. Co-authored-by: Shelley Vohr <[email protected]>
Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
4 tasks done
codebytere
approved these changes
Aug 17, 2026
codebytere
enabled auto-merge (squash)
August 17, 2026 13:18
codebytere
deleted the
trop/43-x-y-bp-perf-don-t-interrupt-the-uv-loop-for-i-o-changes-made-inside-uv_run--1786969331677
branch
August 17, 2026 17:32
|
Release Notes Persisted
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #52862
See that PR for details.
Notes: Reduced idle main-process CPU wakeups caused by Node.js timers and immediates.