pants icon indicating copy to clipboard operation
pants copied to clipboard

Benchmark various defaults for PEX compression for internal PEXes

Open stuhood opened this issue 2 years ago • 8 comments

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

stuhood avatar Apr 07 '22 22:04 stuhood

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?

huonw avatar Apr 22 '23 01:04 huonw

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.

jsirois avatar Apr 22 '23 01:04 jsirois

Has anyone tried seeing whether PEX files might start up a little faster too if they're uncompressed?

cosmicexplorer avatar Jul 24 '23 18:07 cosmicexplorer

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.

jsirois avatar Jul 24 '23 18:07 jsirois

Oh yes! Thanks!

cosmicexplorer avatar Jul 24 '23 18:07 cosmicexplorer

To underscore - the benchmark here is about PEX creation time then, not run time.

jsirois avatar Jul 24 '23 18:07 jsirois

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

huonw avatar Dec 14 '23 03:12 huonw

(#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.)

huonw avatar Dec 30 '23 06:12 huonw