Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lebaudantoine opened this issue Jul 27, 2023 · 1 comment
Open

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

lebaudantoine opened this issue Jul 27, 2023 · 1 comment
Milestone

Comments

@lebaudantoine
Copy link
Contributor

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!

@lebaudantoine
Copy link
Contributor Author

lebaudantoine commented Aug 4, 2023

According to the uvicorn documentation, the framework installs "Cython-based" dependencies like uvloop and httptools "if possible".

Using uvicorn, should automatically install and utilize the uvloop event loop, same for httptools.

While it's safe to assume that using uvicorn would generally address points 1 and 2, let's explore the actual implementation to understand the specific conditions that determine whether these optimizations can be applied, and if there are indeed used by Ralph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo
Development

No branches or pull requests

2 participants