The 40x Slowdown Nobody Warned Me About
Pydantic validation added 847ms to a function that should have taken 21ms. That's not a typo—a simple data transformation went from "instant" to "why is the user staring at a loading spinner?" The culprit wasn't network latency or database queries. It was type validation on 50,000 dictionary objects.
Python type hints have zero runtime cost by design. PEP 484 explicitly states that type annotations should not affect program semantics. But Pydantic, attrs with validators, and beartype don't just annotate—they actively check every field on every object instantiation. When you're processing batch data or handling high-throughput APIs, that "safe" validation becomes a performance tax you didn't budget for.
Why Type Hints Themselves Cost Nothing (But Validation Does)
Let's establish the baseline. Python's native type hints are stored in __annotations__ and completely ignored at runtime:
python
import timeit
def process_untyped(x, y, z):
return x + y + z
---
*Continue reading the full article on [TildAlice](https://tildalice.io/pydantic-40x-validation-overhead-performance/)*

Top comments (0)