You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a synchronous function is used as a dependency factory for FastAPI, the framework runs the function on a threadpool. This is done even if the factory never does IO, which can be quite wasteful. Since it's super tempting to not async-color the function when it's doing something super simple, it seems like it'd be useful to lint for this to avoid potential performance pitfalls.
I think the challenge with a rule such as this is how Ruff should quantify "a small non-IO operation"
And threads here also come with a price and limitations, that are redundant, if you just make a small non-I/O operation.
I worry that suggest a rule would have a high false positive rate. It might be a better fit for Ruff once we have a "suggestion" severity that only applies to the IDE context.
When a synchronous function is used as a dependency factory for FastAPI, the framework runs the function on a threadpool. This is done even if the factory never does IO, which can be quite wasteful. Since it's super tempting to not async-color the function when it's doing something super simple, it seems like it'd be useful to lint for this to avoid potential performance pitfalls.
See https://github.com/zhanymkanov/fastapi-best-practices?tab=readme-ov-file#prefer-async-dependencies for more info.
The text was updated successfully, but these errors were encountered: