Performance: Why async improves performance
HIGH IMPACT
Async improves server responsiveness and throughput by allowing concurrent handling of requests without blocking, which speeds up response time and reduces waiting.
from fastapi import FastAPI import asyncio app = FastAPI() @app.get("/async") async def async_endpoint(): await asyncio.sleep(2) # non-blocking wait return {"message": "done"}
from fastapi import FastAPI import time app = FastAPI() @app.get("/sync") def sync_endpoint(): time.sleep(2) # blocking wait return {"message": "done"}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Synchronous blocking endpoint | N/A (server-side) | N/A | N/A | [X] Bad |
| Asynchronous non-blocking endpoint | N/A (server-side) | N/A | N/A | [OK] Good |