Great read! Python asyncio can really screw up your runtime performance if you use it poorly. And it's _really_ easy to use poorly. Consider a FastAPI server using asyncio instead of threading. _Any_ time you drop down into a synchrononous API, you better be sure that you're not doing anything slow. For example, encoding or decoding JSON in Python actually grabs the GIL depending on what library you're using, and the…
JSON encoding is, as someone else points out, a GIL problem, but I want to add that even if you do JSON encoding in an async context: async def foo(…): json.dumps(d) # you're blocking the event loop You're still going to block on it. def sync_foo(…): json.dumps(d) # you're holding the GIL … and so blocking here too Short of resolving the GIL somehow (either by getting ridding of it, which I think is still a WIP thoug…
I think a lot of people assume you can slap `async` onto the function signature and it will not block anything anymore. I've had PRs come through that literally added `async` to a completely synchronous function with that misunderstanding.