From f222fe6a3a0750d1dfdb74f8db817c8f9f5b7236 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 9 Feb 2023 20:56:09 +1100 Subject: [PATCH] Build: enable Python optimizations (PGO & LTO) on Linux This is used for most Python release builds and has been reported to give a modest 5-10% speedup (depending on the workload). This could be enabled on macOS too but needs to be tested. --- build_files/build_environment/cmake/python.cmake | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/build_files/build_environment/cmake/python.cmake b/build_files/build_environment/cmake/python.cmake index 4d9f892e729..d7f0ae242a2 100644 --- a/build_files/build_environment/cmake/python.cmake +++ b/build_files/build_environment/cmake/python.cmake @@ -88,6 +88,18 @@ else() export LDFLAGS=${PYTHON_LDFLAGS} && export PKG_CONFIG_PATH=${LIBDIR}/ffi/lib/pkgconfig) + # NOTE: untested on APPLE so far. + if(NOT APPLE) + set(PYTHON_CONFIGURE_EXTRA_ARGS + ${PYTHON_CONFIGURE_EXTRA_ARGS} + # Used on most release Linux builds (Fedora for e.g.), + # increases build times noticeably with the benefit of a modest speedup at runtime. + --enable-optimizations + # Also used for Fedora's release builds. + --with-lto + ) + endif() + ExternalProject_Add(external_python URL file://${PACKAGE_DIR}/${PYTHON_FILE} DOWNLOAD_DIR ${DOWNLOAD_DIR}