-
Notifications
You must be signed in to change notification settings - Fork 3.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
PERF: proof of concept, parallel installation of wheels #12816
base: main
Are you sure you want to change the base?
Conversation
I recently opened an issue on this given uv did this with almost no reported issues. One issue I did notice since I posted was this one: astral-sh/uv#4328 So it's definitely a test case that should be checked. There are other edge cases I would be concerned about as well, e.g. What about two packages of the same name? What if one was editable and the other was not? |
That one is an issue on windows. It's hard to tell what uv is doing because it's working from some cache with hardlinks or symlinks. pip extraction always erases an existing file (call to
Quick thoughts, I wonder if a solution would be to have a write lock per package directory,
I think that makes no sense from the installation perspective. The installation loop runs after the resolver. The resolver should have resolved what packages to install. i.e. one package per name. |
This isn't something that is on our radar, but nonetheless, your testing and data is appreciated! |
I'm going to convert this to a draft as it isn't meant to be merged anyway. I'm trying to filter the open PRs by PRs that have a chance of being merged (in an effort to shrink the PR backlog) and I've seen this too many times :) |
Hello,
This is a proof of concept to install wheels in parallels.
Mostly to demonstrate that it's possible.
That took a whole 10 minutes of ChatGPT to parallelize your code :D (and a whole week of debugging pip for other performance issues to understand how to go about it).
I don't expect that to be merged, however if somebody wants to add a proper optional argument
--parallel-install=N
, it should be possible to merge.There are two ways to go about parallelizing the pip installation:
It's pretty easy to do with a ThreadPool. It could be a done with a ProcessPool for a lot more performance improvements, but it's problematic to manage errors with sub processes and I'm not sure fork/processpool are implemented in all systems that pip has to support.
So let's investigate what gain you can get with a simple ThreadPool :)
Turns out, there isn't much to get because of the GIL, unless your filesystem has very high latency (NFS).
You get a small gain with 2 threads, usually no more improvement with 3 threads, it gets worse with 4+ threads.
I note there are multiple critical bugs in pip that makes the extraction very slow and inefficient and hold the GIL.
There should be room for more improvements after all these PRs are merged:
pending PR: #12803
pending PR: #12782
pending PR for download, don't try to parallelize downloads without that fix #12810
some benchmarks below on different types of disks:
above: run on NFS, NFS is high latency and the gains are substantial
above: run on two different disks, /tmp that should be in memory or kind of, and a local volume that is block storage on a virtual machine.
above: run with larger packages to compare.
tensorflow is 1-2 GB extracted
pandas+numpy numba+llvmlite scikitlearn are around 50-100 MB each.
I do note that pip seems to install packages alphabetically, which is not ideal.
tensorflow (and torch) fall toward the very end and I'd rather they start toward the beginning. A lot of the extraction time is waiting at the end for the final package tensorflow to finish extracting. It would complete sooner if it started sooner.