Pip install performance improvements on Windows - #14286
khmyznikov wants to merge 4 commits into
Conversation
Use bounded worker threads for sufficiently large wheels while preserving ordered diagnostics, deterministic bytecode output, and safe self-upgrades. Keep overlapping output paths serial and retain stdout stream behavior. Copilot-Session: ad09eb5a-b18e-4bb2-9225-d2d3d589452e
|
One of the downsides of this approach is non-deterministic byte code, e.g. python/cpython#129724, so you aren't guaranteed "byte-for-byte reproducibility" regardless. |
|
@notatallshaw yeah, that's why I've opened similar issue... Do you think that fixable in theory? |
No, the issue I linked isn't related to free threading, and if you read it (and the linking issues) I think it's unlikely going to be fixed unless someone figures out something clever: python/cpython#129724 (comment) |
|
@notatallshaw python/cpython#156862 is this might be right? I see both regressions and gains, I'm trying to understand is it valuable to continue this direction or it's likely no go? |
|
@khmyznikov I'm not a core Python developer so I can not advise you on python/cpython#156862 As for this PR, I don't know, I'm unlikely to have motivation to review this any time soon, this approach has been tried a few times before, and every time it suffered that fate of when digging into edge cases it always ended up with blocking issues. If you want to leave it open in case another maintainer is interested please remove all the additional files you've added under tools, they are not something that would be accepted and make the PR gigantic. Feel free to add them as gist links in the PR description, if you think they are worth addition context. |
What does this PR do?
Towards #12712.
On Windows, bytecode compilation for large wheels can be dominated by
filesystem and real-time antivirus scanning. This PR compiles Python files from
wheels containing at least eight such files with a bounded
ThreadPoolExecutor. The worker count respects the process-available CPU countand is capped at eight. Smaller wheels and all non-Windows platforms retain the
existing serial path.
This approach avoids the interpreter startup and pip self-upgrade hazards of
process- or subinterpreter-based workers: no additional interpreter imports pip
while its installed files may be replaced.
The parallel path is designed to preserve existing behavior:
RECORDupdates remain in source order..pycoutput path, includingcase-insensitive Windows aliases, are compiled serially.
ordered diagnostics without replacing process-wide
sys.stdout.exhaustion falls back to serial compilation.
close.
--no-parallel-compileretains bytecode compilation while forcing the serialpath.
Supporting benchmark and free-threaded determinism artifacts are available in
this gist.
The benchmark creates deterministic synthetic wheels, interleaves baseline and
candidate runs, reports Defender state, and verifies installed-file hashes. The
reproducer supports python/cpython#156504.
A representative CPython 3.14 run with Microsoft Defender real-time, IOAV, and
behavior monitoring enabled measured:
All compiled-install snapshots were byte-for-byte identical. A 1,200-file
--no-compilecontrol was unchanged within run-to-run noise.Representative-wheel measurements were also collected in a Windows 11 Hyper-V
VM using CPython 3.14.7 with four process-available CPUs. Microsoft Defender
antivirus, real-time protection, IOAV protection, and behavior monitoring were
enabled. Each value is the median of three balanced
pip install --prefixruns:
The ReFS volume was a trusted Dev Drive, and
fsutilreported thewespandWdFilterantivirus filters attached. Its smaller incremental gains areexpected because Defender's Dev Drive performance mode already removes much of
the filesystem-scanning bottleneck. All baseline, candidate-serial, and
candidate-parallel installed-file snapshots were byte-for-byte identical.
Validation includes:
current upstream.
free-threaded.
sys.stdout,serial opt-out, pool failure fallback, exception propagation, and executor
lifecycle coverage.
This also adds
news/12712.feature.rst.PR Checklist:
Assisted-by: GitHub Copilot CLI