FastAPI 0.140.1 has been released with a single but impactful change: an increase to the LRU cache limit for dependency results. This refactor, contributed by @tiangolo in PR #16062, addresses performance bottlenecks in large applications with many dependencies.
Specifically, the update modifies the internal use of @functools.lru_cache applied to dependency calls. Previously, the cache was limited to a relatively small number of entries (e.g., the default maxsize=128). For apps with a high number of unique dependency instances—such as those using path operation dependencies, Depends() with different parameters, or dependencies that vary per request—this low limit caused frequent cache evictions. These evictions, in turn, meant that dependencies were re-executed more often, increasing latency and CPU overhead.
The notable changes include:
- LRU cache limit increased: The
maxsizeparameter forlru_cacheon internal dependency resolution functions has been raised to accommodate a larger number of distinct dependency calls. - Improved performance for large apps: Applications with hundreds or thousands of unique dependency instances will see fewer cache misses, reducing redundant computation and speeding up request handling.
- Backward compatible: This change is non-breaking; it simply optimizes existing behavior without altering the public API or dependency semantics.
For developers, this matters because FastAPI applications often rely heavily on Depends() for database sessions, authentication, and other reusable logic. As apps scale in features and routes, the dependency tree can become complex. A small cache limit could silently slow down performance, especially under high concurrency. With 0.140.1, the framework now scales more gracefully, avoiding unnecessary recalculations of dependencies that haven't changed. To benefit, simply upgrade via pip install --upgrade fastapi.
Source: https://github.com/fastapi/fastapi/releases/tag/0.140.1