New Python Recommendations: Debug and PGO Builds

By Jérôme Vieilledent, on Sep 14, 2021

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:

  1. When a debug build of Python is used in production;
  2. 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!

Recommendations are available for all paid plans (Profiler, Premium, and Enterprise plans). What about giving it a try for free? 15 days evaluation and no credit card required!

Happy Performance Optimization 🐍!

Jérôme Vieilledent

As a Developer Advocate, Jérôme is all about spreading the love! His technical/development background enable him to talk as a peer to peers with our developer users. You’ll read his tips and advices on performance management with Blackfire. And he’ll support you as a day-to-day user.