pants
pants copied to clipboard
Benchmark various defaults for PEX compression for internal PEXes
Pants uses lots of PEXes "internally", which are never exported for users to consume. Since these are implementation details, we have free-rein to choose an internal-default PEX compression level... and some values can make a considerable difference in performance.
To experiment/adjust for "internal only", logic similar to the logic for PEX's layout
setting could be added, which set a default compression value for internal use: https://github.com/pantsbuild/pants/blob/902d3acb84c1b64c53c05e882200e4d578884c03/src/python/pants/backend/python/util_rules/pex.py#L196-L198
Are there internal PEX that aren't PACKED
(grepping for layout=
, PexLayout.
and internal_only=
suggests no)? If all of them are packed, will lowering the compression level do anything?
Yes. A packed layout consists of N + 1 zips. 1 PEX .bootstrap
code zip and 1 per installed wheel contained in the PEX under .deps/
. By default these N+1 are compressed, but turning off compression turns off their compression just as it does for a single zip zipapp layout.
Has anyone tried seeing whether PEX files might start up a little faster too if they're uncompressed?
All PEX files are ~uncompressed (unzipped). Whether --venv
or normal (zipapp), and regardless of --layout
, A PEX file is extracted in one way or another on 1st run and forever more just re-directs to the extracted location. The re-direct overhead is ~O(50ms) except when using --sh-boot
which takes it down to ~1ms.
Oh yes! Thanks!
To underscore - the benchmark here is about PEX creation time then, not run time.
With https://github.com/pantsbuild/pex/releases/tag/v2.1.154, potentially we could be considering using --no-pre-install-wheels
for internal PEXes, and maybe --max-install-jobs
. Quoting https://github.com/pantsbuild/pex/issues/2292#issuecomment-1854582647, for perf results with PyTorch (i.e. large):
Status quo | With --no-pre-install-wheels | --no-pre-install-wheels | savings |
---|---|---|---|
Cold build and run 1st local machine | 188.51s | 29.80s | 84% faster |
Cold run 1st remote machine | 26.74s | 29.60s | 11% slower |
Cold run 1st remote machine parallel | 12.79s | 14.06s | 10% slower |
Size (bytes) | 2679282217 | 2678537958 | 0.02% smaller |
(#20347 updates to pex 2.1.155 by default, but doesn't touch version_constraints
, so if we actually start using that flag internally we'll need to either bump the constraints or make it conditional on version.)