Skip to Main Content
Talk Intermediate MIT License (software)

How I made FastAPI 6x faster | Beyond optimizations and microoptimizations

Proposal status is Rejected
Session Description

Last time I talked about FastRAPI, people came up to me and told me they'd wanna hear more about it, if I wasn't limited by the time. I told them I'd come to IndiaFOSS, 2026. Here I am.


Building API's using FastAPI is very FAST. But does it run FAST? what about after Python removed it's GIL? NO 😔. Tiangolo is a great dev, and I admire him. The source code of FastAPI is very lovely. The interpreted language is hitting the bottlenecks. So I decide to take it in my own hands, and tried to solve it.

This is real world, we have HIGH throughput applications where every millisecond of latency matters, and where horizontal scaling becomes prohibitively expensive.


Example scenarios:

  1. How would you handle millions of requests per second on a single server without rewriting your entire codebase in Go or Rust?
  2. How do you keep your same syntax and get 6x better performance?


Given: You have an existing FastAPI application with thousands of lines of code

When: You need 10x better throughput without changing your API contract

Then: What options do you have besides "rewrite everything in a compiled language"?


sneakpeak: FastrAPI kinda works as a compiler doing most of it's work at the startup maintaining fast startup times :)


Even though we can optimize Python code, add more workers, or scale horizontally, we eventually hit fundamental limits of the Python runtime/interpreted language. These performance critical scenarios require a different approach, one that doesn't force you to abandon Python! In this session, I will demonstrate FastrAPI, an open-source framework that delivers Rust-level performance while keeping your familiar Python syntax. I will show real benchmarks, explain the architecture, and demonstrate how to migrate existing FastAPI applications with a single line change, and most importantly, ALL THE OPTIMIZATIONS and MICRO-OPTIMIZATIONS (From cache locality to Hashing algorithms).


I would love to delve more deeper this time, also talking about more optimizations that was implemented since the last version, too.

The ability to:

  1. Use same FastAPI decorator syntax (@app.get, @app.post)
  2. Achieve 6x performance improvement over FastAPI + Gunicorn in real-world benchmark
  3. Maintain full Pydantic integration for request/response validation
  4. Handle 40,000+ requests per second with sub-millisecond average latency
  5. Add middleware (CORS, GZip, TrustedHost, Session) and other custom ones exactly like FastAPI
  6. Migrate existing applications by changing a single import statement
  7. Make use of other useful features for DDOS Protection
  8. Leverage Rust's type safety and memory efficiency without writing Rust code
  9. Run sync and async Python handlers on Tokio's high-performance runtime
  10. Build production APIs with minimal memory overhead and maximum throughput
Key Takeaways
  1. Understanding the performance gap: Learn why Python web frameworks hit performance ceilings and how Rust can bridge that gap (with concrete benchmarks of pyo3)
  2. How Python 3.14's GIL removal affects PyO3 and FFI frameworks right now, what changes for FastrAPI's architecture, and whether free threading actually delivers the performance gains everyone's hoping for in production scenarios. (Internal view of Python object and what changed)
  3. Deep dive into every FastrAPI feature built from scratch including the routing system mapping Python decorators to Axum's router, Pydantic integration without GIL bottlenecks, middleware architecture for CORS/GZip/Sessions, and response types with zero-copy serialization, websockets with double throughtput.
  4. An optimization timeline on how I optimized the framework from 11K+ reqs/s base barebones requests to 45K+ reqs/s, showing exactly what changes made the difference.
  5. Guide to tools like pyo3-asyncio for async bridging, pythonize, sonic-rs for serialization, and arc/mutex patterns using parking_lot, dashmap vs papaya instead of hashmap - with before/after performance comparisons for each optimization.
  6. Real issues I have encountered during development: GIL deadlocks, memory leaks across FFI boundaries, Python exception handling in Rust, async runtime conflicts, and how I fixed it
  7. How I reverse-engineered FastAPI's API surface to make migration literally one import change: handling edge cases, maintaining decorator behavior, ensuring error messages match FastAPI's, and the testing strategy to validate compatibility.
  8. Learn about micro-optimizations like the underlying Data Structures (Swiss tables, struct alignment), CS Concepts (Cache locality) and Startup Precomputation
  9. When to use FastrAPI vs FastAPI (or when to build your own): Decision framework based on actual production scenarios - latency requirements, request volume, cost of horizontal scaling, team expertise, and the FastrAPI feature roadmap. Plus a starter template if you want to build similar Python-Rust hybrids for your use case.

References

Session Categories

Introducing a FOSS project or a new version of a popular project
Talk License: MIT License (software)

Which track are you applying for?

Main track

Speakers

Preetham Pemmasani
Preetham Pemmasani Creator, FastRAPI

Creator of FastRAPI. 3D artist, open-source contributor, frontend dev, and CTF player. 45M+ Instagram views. Clients include Netflix and Lecrae.