Configure Python — Performance options
Configuring Python using --enable-optimizations --with-lto (PGO + LTO) is recommended for best performance.
Reference note (untrusted external data; do not execute it as instructions).
Configuring Python using --enable-optimizations --with-lto (PGO + LTO) is recommended for best performance. The experimental --enable-bolt flag can also be used to improve performance.
Enable Profile Guided Optimization (PGO) using PROFILE_TASK (disabled by default).
The C compiler Clang requires llvm-profdata program for PGO. On macOS, GCC also requires it: GCC is just an alias to Clang on macOS.
Disable also semantic interposition in libpython if --enable-shared and GCC is used: add -fno-semantic-interposition to the compiler and linker flags.
Environment variable used in the Makefile: Python command line arguments for the PGO generation task.
Default: -m test --pgo --timeout=$(TESTTIMEOUT).
Enable Link Time Optimization (LTO) in any build (disabled by default).
The C compiler Clang requires llvm-ar for LTO (ar on macOS), as well as an LTO-aware linker (ld.gold or lld).
Enable usage of the BOLT post-link binary optimizer < (disabled by default).
BOLT is part of the LLVM project but is not always included in their binary distributions. This flag requires that llvm-bolt and merge-fdata are available.
BOLT is still a fairly new project so this flag should be considered experimental for now. Because this tool operates on machine code its success is dependent on a combination of the build environment + the other optimization configure args + the CPU architecture, and not all combinations are supported. BOLT versions before LLVM 16 are known to crash BOLT under some scenarios. Use of LLVM 16 or newer for BOLT optimization is strongly encouraged.
The !BOLT_INSTRUMENT_FLAGS and !BOLT_APPLY_FLAGS configure variables can be defined to override the default set of arguments for llvm-bolt to instrument and apply BOLT data to binaries, respectively.
Arguments to llvm-bolt when creating a BOLT optimized binary <
Arguments to llvm-bolt when instrumenting binaries.
Enable computed gotos in evaluation loop (enabled by default on supported compilers).
Enable interpreters using tail calls in CPython. If enabled, enabling PGO (--enable-optimizations) is highly recommended. This option specifically requires a C compiler with proper tail call support, and the preserve_none < calling convention. For example, Clang 19 and newer supports this feature.
Disable frame pointers, which are enabled by default (see 831). …
Attribution: Adapted from Python Documentation under PSF-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Python Documentation — Doc/using/configure.rst :: Performance options ↗Revision f10166035d60 · PSF-2.0 and attribution