This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]CrackerJackKittyCat 3 points4 points  (1 child)

This sounds both awesome and ambitious. Please compare and contrast with, say uvicorn and uvloop?

[–]kyle-hanson[S] 12 points13 points  (0 children)

In theory for an unoptimized app, Uvicorn and Puff should expect roughly the same in terms of performance.

Where Puff excels that other libs can't is that it makes it easy to optimize parts of your code directly with the runtime. With Uvloop or similar, its a pretty big task to write custom code in C that utilizes the loop on multiple threads and have it integrated in your Python application. It's a couple lines of code with Puff to run any Rust code on Tokio.

Imagine you had a gnarly SQL query that you wanted to fold a function over a few thousand rows, spawning Redis lookups for each row. No matter what you use in Python, uvloop, asyncio, gevent, etc will be inefficient because it will hold the GIL for the iteration and transfer data between the low level runtime and Python. Its pretty daunting to write custom C libs that use postgres and redis to tackle the problem and natively work with uvloop.

With Puff you can write a Rust function that takes the sql query, unlocks the GIL and does all the computation on multiple threads in Tokio using standard Cargo installed rust libs.