Performance: Path operation dependencies
MEDIUM IMPACT
This affects the server response time and throughput by adding overhead to each request due to dependency resolution.
from fastapi import FastAPI, Depends app = FastAPI() async def cached_dependency(): return "done" @app.get("/items/") async def read_items(dep=Depends(cached_dependency)): return {"status": dep}
from fastapi import FastAPI, Depends app = FastAPI() def heavy_dependency(): import time time.sleep(1) # Simulate heavy work return "done" @app.get("/items/") async def read_items(dep=Depends(heavy_dependency)): return {"status": dep}
| Pattern | Dependency Cost | Request Delay | Throughput Impact | Verdict |
|---|---|---|---|---|
| Heavy blocking dependency | High CPU or sleep | Adds 1s delay per request | Reduces throughput significantly | [X] Bad |
| Lightweight async dependency | Minimal CPU | Near zero delay | Maintains high throughput | [OK] Good |