New Python Recommendations: Debug and PGO Builds
New recommendations for Python, regarding debug and PGO builds
Blackfire Recommendations give you instant insights and suggestions from the profiles of your application. These suggestions may be performance, quality, or security advice, and we constantly add more of them for all supported languages, including Python.
Lately, we added 2 important recommendations for Python:
- When a debug build of Python is used in production;
- Suggestion to use a PGO build.
Debug Build of Python
A debug build of Python may be substantially slower due to various hooks added to the memory allocator and the disablement of compiler optimizations.
Therefore, it is not recommended to use such a build in production.
You can check if your Python interpreter was compiled in debug mode using the following command:
python -c "import sysconfig; print(bool(sysconfig.get_config_var('Py_DEBUG')))"
Profile Guided Optimization (PGO) build of Python
PGO builds are known to be faster than regular ones (~10 to 20% faster). As such, it is always recommended to use such builds in production.
Most Operating Systems come with PGO enabled binaries, but there might be some exceptions (e.g., Ubuntu as of 2021, macOS…).
You can check if your Python interpreter is compiled with PGO using the following command:
python -c "import sysconfig; print('-fprofile-use' in (sysconfig.get_config_var('PY_CFLAGS') + sysconfig.get_config_var('PY_CFLAGS_NODIST')))"
Start your Premium Trial Now!
Happy Performance Optimization 🐍!