Performance: Why validation prevents bad data
MEDIUM IMPACT
Validation affects server response time and client experience by catching errors early and reducing unnecessary processing.
from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class Item(BaseModel): name: str price: float @app.post('/items/') async def create_item(item: Item): process(item.dict()) return {'status': 'success'}
from fastapi import FastAPI app = FastAPI() @app.post('/items/') async def create_item(item: dict): # No validation, assume data is correct process(item) return {'status': 'success'}
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No validation | N/A | N/A | N/A | [X] Bad |
| Automatic validation with Pydantic | N/A | N/A | N/A | [OK] Good |