Performance: Default values
LOW IMPACT
This affects the server response time and request parsing speed by how default values are handled in endpoint parameters.
from fastapi import FastAPI app = FastAPI() @app.get("/items") async def read_items(q: str = "default"): return {"q": q}
from fastapi import FastAPI app = FastAPI() @app.get("/items") async def read_items(q: str = None): if q is None: q = "default" return {"q": q}
| Pattern | CPU Overhead | Code Complexity | Response Time Impact | Verdict |
|---|---|---|---|---|
| Manual default assignment inside endpoint | Slightly higher due to condition check | More complex with extra if statements | Negligible but unnecessary | [X] Bad |
| Using FastAPI default parameter values | Minimal CPU overhead | Simpler and cleaner code | Negligible and optimal | [OK] Good |