Skip to content

⚡️ Improve FastAPI performance by +265% 🚀🚀 #401

@lebaudantoine

Description

@lebaudantoine

These performance improvement tips are from Marcelo Trylesinski, the maintainer of FastAPI. These insights are shared in a LinkedIn post, which you can find here

10 tips for performances improvement :

  1. use uvloop +10%🚀, is a fast, drop-in replacement of the built-in asyncio event loop
  2. use httptools - faster parsing +10%🚀, Python binding for nodejs HTTP parser, you just need to have it installed in your environment
  3. use bigger threadpool +5%🚀
  4. use simple async application, +15%🚀, no overhead of threads
  5. remove duplicate validation, have only FastAPI do the validation +25%🚀
  6. use ORJSON + 5% 🚀(if not using the latest Pydanctic version already)
  7. consider running without validation is an option, 150%, without logging +25%. Both not a general recommendation!
  8. use the most recent version of FastAPI, + 265% 🚀- this is related to pydantic going rust
  9. use ASGI Middleware: see https://lnkd.in/eUW5-bwG
  10. compress responses

Stay tuned for the recording of the conference, which will be released on the EuroPython channel in a few weeks, allowing us to dive deeper into these performance-boosting techniques. Happy optimizing!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Todo

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions