nixpkgs/pkgs/development/interpreters/python
Greg Price f8a8243bd3 cpython: Use --enable-optimizations, for a 16% speedup.
Without this flag, the configure script prints a warning at the end,
like this (reformatted):

  If you want a release build with all stable optimizations active
  (PGO, etc), please run ./configure --enable-optimizations

We're doing a build to distribute to people for day-to-day use,
doing things other than developing the Python interpreter.  So
that's certainly a release build -- we're the target audience for
this recommendation.

---

And, trying it out, upstream isn't kidding!  I ran the standard
benchmark suite that the CPython developers use for performance
work, "pyperformance".  Following its usage instructions:
  https://pyperformance.readthedocs.io/usage.html
I ran the whole suite, like so:

  $ nix-shell -p ./result."$variant" --run '
      cd $(mktemp -d); python -m venv venv; . venv/bin/activate
      pip install pyperformance
      pyperformance run -o ~/tmp/result.'"$variant"'.json
    '

and then examined the results with commands like:

  $ python -m pyperf compare_to --table -G \
      ~/tmp/result.{$before,$after}.json

Across all the benchmarks in the suite, the median speedup was 16%.
(Meaning 1.16x faster; 14% less time).

The middle half of them ranged from a 13% to a 22% speedup.

Each of the 60 benchmarks in the suite got faster, by speedups
ranging from 3% to 53%.

---

One reason this isn't just the default to begin with is that, until
recently, it made the build a lot slower.  What it does is turn on
profile-guided optimization, which means first build for profiling,
then run some task to get a profile, then build again using the
profile.  And, short of further customization, the task it would use
would be nearly the full test suite, which includes a lot of
expensive and slow tests, and can easily take half an hour to run.

Happily, in 2019 an upstream developer did the work to carefully
select a more appropriate set of tests to use for the profile:
  https://github.com/python/cpython/commit/4e16a4a31
  https://bugs.python.org/issue36044
This suite takes just 2 minutes to run.  And the resulting final
build is actually slightly faster than with the much longer suite,
at least as measured by those standard "pyperformance" benchmarks.
That work went into the 3.8 release, but the same list works great
if used on older releases too.

So, start passing that --enable-optimizations flag; and backport
that good-for-PGO set of tests, so that we use it on all releases.
2020-05-11 23:37:04 -07:00
..
catch_conflicts
cpython cpython: Use --enable-optimizations, for a 16% speedup. 2020-05-11 23:37:04 -07:00
graalpython pythonInterpreters.graalpython37: init 2019-10-22 09:16:18 +02:00
hooks python: add pythonRemoveTestsDirHook 2020-03-03 20:01:00 +01:00
manylinux Fix manylinux packages 2019-12-13 11:40:44 +01:00
pypy pypy{,3}: use openssl_1_1 2020-02-28 16:06:20 +00:00
tests Python: introduce tests for interpreters 2020-03-14 15:05:37 +01:00
update-python-libraries python: add use-pkgs-prefix option to update script 2020-03-27 01:47:30 -07:00
default.nix Python: introduce tests for interpreters 2020-03-14 15:05:37 +01:00
fetchpypi.nix pythonPackages.fetchPypi: support SRI hashes 2019-07-11 18:01:04 +02:00
mk-python-derivation.nix python: add pythonRemoveTestsDirHook 2020-03-03 20:01:00 +01:00
run_setup.py
setup-hook.nix
setup-hook.sh python: make it possible to disable the python setup-hook 2019-04-28 09:20:41 +02:00
sitecustomize.py Python: introduce NIX_PYTHONEXECUTABLE in order to set sys.executable 2019-07-27 11:52:49 +02:00
tests.nix Python: introduce tests for interpreters 2020-03-14 15:05:37 +01:00
with-packages.nix
wrap-python.nix Python: improve cross-compilation 2019-01-04 10:45:22 +01:00
wrap.sh python.pkgs.wrapPython: get rid of warning 2019-12-30 16:46:55 +01:00
wrapper.nix Python: introduce NIX_PYTHONEXECUTABLE in order to set sys.executable 2019-07-27 11:52:49 +02:00