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

Proactively build wheels for source distributions during pip install resolution #2703

Open
charliermarsh opened this issue Mar 28, 2024 · 4 comments
Labels
performance Potential performance improvement

Comments

@charliermarsh
Copy link
Member

charliermarsh commented Mar 28, 2024

When we pip install, we first run the resolver, then use the resolution to install. If we encounter a source distribution while resolving, we'll attempt to get the metadata, which may involve running prepare_metadata_for_build_wheel as an optimization, to skip the wheel build. After the resolution, we need to install, so we go to build the wheel, which requires creating the build environment again.

This is somewhat wasteful, since we had to setup the build environment twice. If we know we'll need to include the distribution in the resolution, and we know that we're going to need to install (as in pip install or pip sync, but not pip compile), we should consider always building the distribution and avoiding prepare_metadata_for_build_wheel.

This could make sense for, e.g., direct URL distributions that we encounter during pip install and pip sync resolutions.

I don't know how much this matters, but it did occur to me today, since we're now doing more metadata resolutions during pip install. We should verify before changing anything, but in https://github.com/timothyjlaurent/uv-poetry-monorepo-mre, my estimate is that it cost us about 150ms.

@charliermarsh charliermarsh added the performance Potential performance improvement label Mar 28, 2024
@potiuk
Copy link

potiuk commented Mar 28, 2024

I think it's a good idea taking into acount all the dynamic complications - and also it follows the path that PEP 660 took for editable builds https://peps.python.org/pep-0660/. For dependencies that you indeed know that you have to install and you know that this is the version you are going to install for sure (URL. local paths) as you noted this will make the resolution a bit longer, but overall impact on installation time will be net-negative. It will also allow to avoid the cases like we had with making some exceptions for specific cases like in #2130

@charliermarsh
Copy link
Member Author

Just to clarify, I think this should be faster when we know we need to install the wheel eventually.

@charliermarsh
Copy link
Member Author

The downside here is that we may end up reducing the amount of parallelism if we're waiting on source distributions to build during resolution.

@charliermarsh
Copy link
Member Author

We could safely do this in pip sync and pip install --no-deps with no penalty though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Potential performance improvement
Projects
None yet
Development

No branches or pull requests

2 participants