Repository navigation
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
Documentation build overview
22 files changed ·
|
asvetlov
force-pushed
the
eager-loop
branch
5 times, most recently
from
October 28, 2026 14:53
f3f2dfe to
2950322
Compare
…e polling for I/O After running the ready callbacks, BaseEventLoop._run_once() now keeps running the callbacks they schedule, in batches, before it polls for I/O again. This saves one I/O poll per hop of a callback chain, for example when a completed future wakes up a task. Eager processing is bounded by the new asyncio.EventLoopSettings, set with loop.set_settings() and read with loop.get_settings(): eager_max_time (default 100 microseconds) and eager_max_callbacks (default 100). asyncio.sleep(0) ends eager processing, so that the task resumes only after the next I/O poll. When stop() is called during eager processing, run_forever() runs one more iteration, which polls for I/O and runs what the loop would have run without eager processing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Run callbacks that are scheduled during an event loop iteration eagerly, within a small budget, instead of always waiting for the next I/O poll. This removes one
select()/epoll_wait()call per hop in code that resolves futures or wakes tasks in chains.asyncio.EventLoopSettings(eager_max_time, eager_max_callbacks)andloop.get_settings()/loop.set_settings(). The defaults are 100 µs and 100 callbacks;eager_max_time=0turns eager processing off.asyncio.sleep(0), which still guarantees an I/O poll, and onloop.stop(), which keeps its documented "current batch only" behaviour.Benchmarks (release build): a
call_soon()chain is 38% faster,Queueping-pong 25% faster, and a task awaiting a child task 33% faster. Servers with many connections are unchanged. While a long run of callbacks keeps going, timers and I/O can be delayed by up to about 100–200 µs.A few tests that assumed "one task hop = one I/O poll" were adjusted.