Is uvloop still faster than built-in asyncio event loop?

If so, why hasn’t the standard asyncio event loop switched to use it?

I’m considering using it, but am suspicious of it magically being faster with no other tradeoffs or concerns. Sounds too good to be true.

Put another way, as an application author, should I use uvloop for performance reasons?

The ecosystem is full of examples like this - orjson is much faster than the json module, structlog can be configured to be much faster than logging, etc. Not everything needs to be in the standard library, where it incurs a maintenance burden on the core devs.

2 Likes

Python is designed with extensibility in mind! If you’re aiming for better performance, consider using uvloop, an ultra-fast event loop for asyncio. For additional performance-focused tools, explore libraries like simdjson and similar options.

I agree with the responses here. I guess I’m hoping for more confirmation regarding uvloop specifically.

I guess I thought that switching the event loop implementation to uvloop wouldn’t be a breaking change (since it’s a “drop in replacement”). I hadn’t considered that, just because it’s API is identical doesn’t mean it is not a maintenance burden

My experience with uvloop has always been great, so I encourage you to try it and see if it’s faster for your use case (almost certainly will be).

1 Like

Does the fact that both PEP 492 and uvloop have the same author reassure you?

2 Likes

Yes it does, thank you for pointing that out

1 Like

In case if you’re interested, I have been working on rsloop, an alternative event loop written in Rust, that in some cases is faster than uvloop: GitHub - RustedBytes/rsloop: An event loop for asyncio written in Rust · GitHub

Aye, it’s the external dependency on libuv that we don’t want to bring into the core interpreter. As a third party module, uvloop can be updated as needed to harmonise different versions of libuv with different versions of Python, but if it’s directly in the standard library, everything gets more annoying to keep aligned.

3 Likes

It is faster. I routinely run a benchmark that checks asyncio vs uvloop among others for different message sizes and TCP vs SSL.

Both uvloop tasks scheduling and networking are faster.

Will switching to uvloop benefit your project depends on the project. For a small business logic and lots of networking I would definitely use uvloop.

I’ve been working on an async I/O engine for Zig for the last year, and took a quick detour and implemented an asyncio evet loop based on the core of the engine. It’s about 10% faster than uvloop in most networking benchmarks (due to running on io_uring by default, and having less abstractions than libuv → uvloop → asyncio), and also faster at raw callbacks/tasks, but along the way I realized it does not really care, because the moment you add a Python framework, the performance gets significantly reduced. The only reason for me bringing the project to an usable state was that it also has async file I/O, which is currently hard to get on asyncio otherwise.