-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Execute dependencies in parallel instead of sequentially awaiting them #639
Comments
that's indeed a good idea |
This seems like a good idea. But I think it would be quite non-trivial to implement. It would require sorting and finding the dependencies before running them, to be able to know what can be parallelizable that doesn't require something else first. But if you feel like trying to take a stab at it, a PR would be more than welcome. 💪 |
Hey @tiangolo , just a heads up it looks like @ariloulaleelay has a PR up to implement this in #3902, and I've also worked out how to do it in di (which is based on FastAPI's DI system), so there's at least a couple ideas on how to move forward with this 😄 |
I'm wondering what's up with this issue. I noticed that PR #3902 for it was closed by the PR's author in May 2022. I've been investigating an overhead of 30ms-100ms depending on hardware performance, wondering if this could get that overhead down. |
Nobody wanted that PR been merged. So I gave up and closed it. |
Is this issue not resolved yet? It would be very useful if improved. |
Is your feature request related to a problem? Please describe.
FastAPI's Dependency injection system, while extremely useful, tends to run into a problem when several long-running dependencies are needed for a single route, such as with the example below.
Running that application and thentrying to access
/do_long_thing
takes 15 seconds to load, even though none of those dependencies are reliant on each other and could very well be ran in parallel.Describe the solution you'd like
Don't await coroutines and threadpools here. Collect them into a list instead and gather them.
fastapi/fastapi/dependencies/utils.py
Lines 442 to 456 in 3f9f4a0
Describe alternatives you've considered
Asking that the user take care of running and gathering those dependencies themselves is pretty much the only solution to this problem available right now (that I can see, anyway, there might be another one), which undermines the usefulness of the dependency injection system.
The text was updated successfully, but these errors were encountered: