Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does --enable-optimizations do while compiling python?

I'm trying to compile Python 3.6 on an arm based Linux machine, ./configure outputs this:

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

what does --enable-optimizations do?

like image 575
Yashar Avatar asked Dec 31 '16 05:12

Yashar


People also ask

What is enable optimization?

Enable Optimization (-O)Enables maximum performance at run time by carrying out the minimum run-time checks. This option is for use after all debugging has taken place and maximum performance with minimum run-time checks is required.

How does link time optimization work?

Link Time Optimization is a form of interprocedural optimization that is performed at the time of linking application code. Without LTO, Arm Compiler for Linux compiles and optimizes each source file independently of one another, then links them to form the executable.


1 Answers

This flag enables Profile guided optimization (PGO) and Link Time Optimization (LTO).

Both are expensive optimizations that slow down the build process but yield a significant speed boost (around 10-20% from what I remember reading).

The discussion of what these exactly do is beyond my knowledge and probably too broad for a single question. Either way, you can read a bit about LTO from the the docs on GCC which has an implementation for it and get a start on PGO by reading its wiki page.

Also, see the relevant issues opened on the Python Bug Tracker that added these:

  • Issue 24915: Profile Guided Optimization improvements (better training, llvm support, etc) (Added PGO.)
  • Issue 25702: Link Time Optimizations support for GCC and CLANG (Added LTO.)
  • Issue 26359: CPython build options for out-of-the box performance (Adds the --enable-optimizations flag to the configure script which enables the aforementioned optimizations.)

As pointed out by @Shuo in a comment and stated in Issue 28032, LTO isn't always enabled with the --enable-optimizations flag. Some platforms (depending on the supported version of gcc) will disable it in the configuration script.

Future versions of this flag will probably always have it enabled though, so it's pretty safe to talk about them both here.

like image 151
Dimitris Fasarakis Hilliard Avatar answered Oct 01 '22 10:10

Dimitris Fasarakis Hilliard