classification
Title: CPython build options for out-of-the box performance
Type: performance Stage: resolved
Components: Build Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: 21122 Superseder:
Assigned To: gregory.p.smith Nosy List: alecsandru.patrascu, brett.cannon, gregory.p.smith, haypo, lemburg, ned.deily, pitrou, python-dev, r.david.murray, scoder, skrah, steve.dower, zach.ware
Priority: normal Keywords: patch

Created on 2016-02-14 10:28 by alecsandru.patrascu, last changed 2017-03-31 16:36 by dstufft. This issue is now closed.

Files
File name Uploaded Description Edit
cpython2_pgo_default-v01.patch alecsandru.patrascu, 2016-02-14 10:28 review
cpython3_pgo_default-v02.patch alecsandru.patrascu, 2016-02-14 10:28 review
cpython3_with_optimizations_v01.patch alecsandru.patrascu, 2016-04-23 08:52 review
cpython2_with_optimizations_v01.patch alecsandru.patrascu, 2016-05-16 12:37 review
cpython3_with_optimizations_v02.patch alecsandru.patrascu, 2016-05-16 12:37 review
cpython2_with_optimizations_v02.patch alecsandru.patrascu, 2016-06-03 07:51 review
cpython3_with_optimizations_v02-gps01.patch gregory.p.smith, 2016-09-06 22:40 review
issue26359.diff brett.cannon, 2016-09-07 00:02 review
Pull Requests
URL Status Linked Edit
PR 552 closed dstufft, 2017-03-31 16:36
Messages (32)
msg260271 - (view) Author: Alecsandru Patrascu (alecsandru.patrascu) * Date: 2016-02-14 10:28
Hello,

This is Alecsandru from the Dynamic Scripting Languages Optimization Team at Intel Corporation. I would like to submit a patch as a response to the discussion thread opened in Python-Dev (https://mail.python.org/pipermail/python-dev/2016-February/143215.html), regarding the way CPython is built, mainly the options that are available to the programmers. Analyzing the CPython ecosystem we can see that there are a lot of users that just download the sources and hit the commands "./configure", "make" and "make install" once and then continue using it with their Python scripts. One of the problems with this workflow it that the users do not benefit from the entire optimization features that are existing in the build system, such as PGO and LTO.

Therefore, I propose a workflow, like the following. Assume some work has to be done into the CPython interpreter, a developer can do the following steps:
A. Implementation and debugging phase. 
    1. The command "./configure PYDIST=debug" is ran once. It will enable the Py_DEBUG, -O0 and -g flags
    2. The command "make" is ran once or multiple times
    
B. Testing the implementation from step A, in a pre-release environment
    1. The command "./configure PYDIST=devel" is ran once. It will disable the Py_DEBUG flags and will enable the -O3 and -g flags, and it is just like the current implementation in CPython
    2. The command "make" is ran once or multiple times

C. For any other CPython usage, for example distributing the interpreter, installing it inside an operating system, or just the majority of users who are not CPython developers and only want to compile it once and use it as-is:
    1. The command "./configure" is ran once. Alternatively, the command  "./configure PYDIST=release" can be used. It will disable all debugging functionality, enable the -O3 flag and will enable PGO and LTO.
    2. The command "make" is ran once
    
Thank you,
Alecsandru
msg263353 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2016-04-13 19:23
Sorry, I don't understand this issue. I don't think that we need 3 flavors: debug, devel and release. We already have debug (--with-pydebug) and release, and IMHO debug is what developers should use.

I like the idea of using the best optimizers options *by default* for the release mode. In practice, I suggest to enable PGO *by default*.
msg263372 - (view) Author: Alecsandru Patrascu (alecsandru.patrascu) * Date: 2016-04-14 07:16
Hello Victor, 

Indeed, the best outcome is to have PGO, LTO, etc enabled by default when running ./configure && make, for production level. I also feel that they should be on by default, if only developers would use the debug version.

Do you think that modifying the patches attached to this issue and enabling all optimizations by default could be considered acceptable by the Python community?

Thank you,
Alecsandru
msg263374 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2016-04-14 07:42
Not acceptable, I'm afraid. See #25702.  I'm not sure why it is
considered so bothersome to type --with-pgo and --with-lto for
the rare case of a real production build.
msg263384 - (view) Author: Alecsandru Patrascu (alecsandru.patrascu) * Date: 2016-04-14 08:41
Maybe that end users are lazy and want to type just `make` and let things happen magically behind the scenes :-)
msg263408 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-04-14 13:46
FWIW, I'm also against enabling it by default due to the extended build time. There are plenty of reasons to build Python with the non-debug ABI that don't require extended optimizations. Production builds are the exception I believe, not the rule.
msg263415 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-04-14 15:25
What if we added a --with-optimizations flag to build --with-pgo, --with-lto, and avoid having to run `make` twice thanks to `make`/`make profileopt`? That way the default build is still quick and reasonable but gain a simple way to use the right flags and avoid having to remember to run `make` twice?
msg263452 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2016-04-15 06:47
--with-optimizations seems fine.

As does having the final thing the Makefile prints out when run from a configuration that did not specify any of --with-pgo, --with-lto, --with-pydebug, or --with-optimizations be to echo message reminding people to configure --with-optimizations when making a release build.

The default "./configure && make" target needs to remain optimized for CPython developer speed.  Not release builds.
msg263466 - (view) Author: Alecsandru Patrascu (alecsandru.patrascu) * Date: 2016-04-15 10:17
That sounds like a good idea and plan, to have everything enabled with just one dedicated configure flag.

I can work on this and post the patches as soon as they are done. 

Thank you
msg264058 - (view) Author: Alecsandru Patrascu (alecsandru.patrascu) * Date: 2016-04-23 08:52
I've added the --with-optimizations option to configure, for CPython3 only at this point. If it looks good I'll create a version also for CPython2.
msg265432 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-05-12 22:48
The patch LGTM but I'm not a configure/make expert. Anyone else want to have a look?

Alecsandru, if no one takes a look within the next week then just assign the issue to me.
msg265692 - (view) Author: Alecsandru Patrascu (alecsandru.patrascu) * Date: 2016-05-16 12:40
I've attached a cleaner version for CPython 3 and one for CPython 2. The problem with CPython 2 is that Gregory did not yet merged the LTO on this branch (#25702), but as soon as he does it, I'll post updated patches.

Regards,
Alecsandru
msg265693 - (view) Author: Alecsandru Patrascu (alecsandru.patrascu) * Date: 2016-05-16 12:43
Brett, I tried to add you in the "assigned to", but I do not have any rights to update those :(
msg265699 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-05-16 15:39
Just leave a comment next week in the issue if no one else beats me to the issue (I'm at OSCON so I don't have time to commit until May 24 at the earliest).
msg266735 - (view) Author: Alecsandru Patrascu (alecsandru.patrascu) * Date: 2016-05-31 05:57
Hello Brett, I saw that there was no other activity on this issue so far. Can you please update this, as I do not have rights?
msg267074 - (view) Author: Alecsandru Patrascu (alecsandru.patrascu) * Date: 2016-06-03 07:51
I've updated the patch for 2.7 branch to contain the LTO part merged by Gregory.
msg267076 - (view) Author: Alecsandru Patrascu (alecsandru.patrascu) * Date: 2016-06-03 07:54
The patches in discussions are the v02 ones.
msg273936 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-08-30 17:00
Just FYI, Alecsandru, I plan on applying your patches this week or next, so if you can just double-check they still apply cleanly that would be great.
msg274277 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-09-02 22:26
So if I enable this manually, I get various test failures from modules on OS X El Capitan with the same type of failure:

[ 95/398] test_bytes
Traceback (most recent call last):
  File "/Users/brettcannon/Repositories/python/cpython/3.5/Lib/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/Users/brettcannon/Repositories/python/cpython/3.5/Lib/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/brettcannon/Repositories/python/cpython/3.5/Lib/test/__main__.py", line 3, in <module>
    regrtest.main_in_temp_cwd()
  File "/Users/brettcannon/Repositories/python/cpython/3.5/Lib/test/regrtest.py", line 1593, in main_in_temp_cwd
    main()
  File "/Users/brettcannon/Repositories/python/cpython/3.5/Lib/test/regrtest.py", line 756, in main
    raise Exception("Child error on {}: {}".format(test, result[1]))
Exception: Child error on test_bytes: Exit code -6

Since I can't get the test suite to pass with PGO+LTO I'm not comfortable committing this patch and promoting people turn them on.
msg274647 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2016-09-06 22:40
Minor edit to avoid printing the message about --with-optimizations when doing a --with-pydebug build.  otherwise this patch works well on Ubuntu xenial 16.04 amd64.

From discussions in the CPython Core Sprint room today - we've agreed that we should just modify the configure.ac check to not enable --with-lto as part of this when on MacOS until an xcode toolchain for that to work properly on can be figured out.
msg274678 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-09-07 00:00
Here is modification of Greg's patch to turn off LTO under OS X since LTO+PGO do not get along under El Capitan.
msg274679 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-09-07 00:02
Patch with the missing Makefile.pre.in part :P
msg274683 - (view) Author: Roundup Robot (python-dev) Date: 2016-09-07 00:13
New changeset b4b73473ecc6 by Brett Cannon in branch 'default':
Issue #26359: Add the --with-optimizations configure flag.
https://hg.python.org/cpython/rev/b4b73473ecc6
msg274687 - (view) Author: Roundup Robot (python-dev) Date: 2016-09-07 00:17
New changeset 1e61cc86df03 by Brett Cannon in branch '3.5':
Issue #26359: Add the --with-optimizations flag.
https://hg.python.org/cpython/rev/1e61cc86df03

New changeset f9b52b31f1b4 by Brett Cannon in branch 'default':
Merge for #26359
https://hg.python.org/cpython/rev/f9b52b31f1b4
msg274689 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2016-09-07 00:17
Leaving this open in case someone wants to backport to 2.7.
msg274981 - (view) Author: Roundup Robot (python-dev) Date: 2016-09-08 07:09
New changeset bc28cbd49070 by Gregory P. Smith in branch '2.7':
Issue #26359: Add the --with-optimizations flag.
https://hg.python.org/cpython/rev/bc28cbd49070
msg275055 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2016-09-08 15:45
Thanks for the new option.  Perhaps the top-level README should be updated to mention --with-optimizations?
msg275104 - (view) Author: Roundup Robot (python-dev) Date: 2016-09-08 18:34
New changeset e1987bf14148 by Gregory P. Smith in branch '3.5':
document --with-optimizations in the README for issue26359.
https://hg.python.org/cpython/rev/e1987bf14148

New changeset 4afb12077e08 by Gregory P. Smith in branch 'default':
document --with-optimizations in the README for issue26359.
https://hg.python.org/cpython/rev/4afb12077e08
msg275105 - (view) Author: Roundup Robot (python-dev) Date: 2016-09-08 18:38
New changeset 8567bc2876af by Gregory P. Smith in branch '2.7':
document --with-optimizations in the README for issue26359.
https://hg.python.org/cpython/rev/8567bc2876af
msg275172 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2016-09-08 21:34
see https://bugs.python.org/issue28032 for flaws with --with-optimizations builds.
msg281301 - (view) Author: Gregory P. Smith (gregory.p.smith) * (Python committer) Date: 2016-11-20 21:27
per comments in issue28032 the new configure flag has been renamed from --with-optimizations to --enable-optimizations in all branches it was added to:

remote: notified python-checkins@python.org of incoming changeset c0ea81315fb6
remote: notified python-checkins@python.org of incoming changeset 58c1a49a10b4
remote: notified python-checkins@python.org of incoming changeset 11cacf9f9a33
remote: notified python-checkins@python.org of incoming changeset 0d2b42344ae5
remote: notified python-checkins@python.org of incoming changeset 2d1d70b53376
remote: notified python-checkins@python.org of incoming changeset d5ff5a2f33fd
msg288528 - (view) Author: STINNER Victor (haypo) * (Python committer) Date: 2017-02-24 15:35
It seems like it's not possible to install Python configured with --enable-optimizations: see my issue #29641, "make install failure when using ./configure --enable-optimizations.
History
Date User Action Args
2017-03-31 16:36:31dstufftsetpull_requests: + pull_request1048
2017-02-24 15:35:00hayposetmessages: + msg288528
2016-11-20 21:27:49gregory.p.smithsetmessages: + msg281301
2016-09-08 21:34:14gregory.p.smithsetmessages: + msg275172
2016-09-08 18:38:09python-devsetmessages: + msg275105
2016-09-08 18:34:49python-devsetmessages: + msg275104
2016-09-08 15:45:26ned.deilysetnosy: + ned.deily

messages: + msg275055
versions: + Python 3.5, Python 3.6
2016-09-08 07:10:04gregory.p.smithsetstatus: open -> closed
resolution: fixed
stage: resolved
2016-09-08 07:09:25python-devsetmessages: + msg274981
2016-09-08 05:34:26gregory.p.smithsetassignee: gregory.p.smith
2016-09-07 00:17:52brett.cannonsetmessages: + msg274689
versions: - Python 3.5, Python 3.6
2016-09-07 00:17:02python-devsetmessages: + msg274687
2016-09-07 00:13:10python-devsetnosy: + python-dev
messages: + msg274683
2016-09-07 00:02:26brett.cannonsetfiles: - issue26359.diff
2016-09-07 00:02:12brett.cannonsetfiles: + issue26359.diff

messages: + msg274679
2016-09-07 00:00:20brett.cannonsetfiles: + issue26359.diff

messages: + msg274678
2016-09-06 23:08:52gregory.p.smithlinkissue27983 dependencies
2016-09-06 22:40:33gregory.p.smithsetfiles: + cpython3_with_optimizations_v02-gps01.patch

messages: + msg274647
2016-09-02 22:26:32brett.cannonsetmessages: + msg274277
2016-09-02 21:58:08brett.cannonsetassignee: brett.cannon -> (no value)
dependencies: + CPython fails to build modules with LLVM LTO on Mac OS X
2016-08-30 17:00:35brett.cannonsetmessages: + msg273936
2016-06-03 07:54:42alecsandru.patrascusetmessages: + msg267076
2016-06-03 07:51:14alecsandru.patrascusetfiles: + cpython2_with_optimizations_v02.patch

messages: + msg267074
2016-06-02 18:19:23brett.cannonsetassignee: brett.cannon
2016-05-31 05:57:24alecsandru.patrascusetmessages: + msg266735
2016-05-16 15:39:14brett.cannonsetmessages: + msg265699
2016-05-16 12:43:14alecsandru.patrascusetmessages: + msg265693
2016-05-16 12:40:34alecsandru.patrascusetmessages: + msg265692
2016-05-16 12:37:56alecsandru.patrascusetfiles: + cpython3_with_optimizations_v02.patch
2016-05-16 12:37:43alecsandru.patrascusetfiles: + cpython2_with_optimizations_v01.patch
2016-05-12 22:48:26brett.cannonsetmessages: + msg265432
2016-04-23 08:52:42alecsandru.patrascusetfiles: + cpython3_with_optimizations_v01.patch

messages: + msg264058
2016-04-15 10:17:36alecsandru.patrascusetmessages: + msg263466
2016-04-15 06:47:27gregory.p.smithsetmessages: + msg263452
2016-04-14 15:25:06brett.cannonsetmessages: + msg263415
2016-04-14 13:46:45steve.dowersetmessages: + msg263408
2016-04-14 08:41:22alecsandru.patrascusetmessages: + msg263384
2016-04-14 07:42:33skrahsetmessages: + msg263374
2016-04-14 07:16:02alecsandru.patrascusetmessages: + msg263372
2016-04-13 19:23:04hayposetmessages: + msg263353
2016-02-27 16:48:45alecsandru.patrascusetnosy: + lemburg, brett.cannon, gregory.p.smith, pitrou, scoder, r.david.murray, skrah, zach.ware, steve.dower
2016-02-15 21:20:04SilentGhostsetnosy: + haypo
2016-02-14 10:28:23alecsandru.patrascusetfiles: + cpython3_pgo_default-v02.patch
2016-02-14 10:28:12alecsandru.patrascucreate