Pybind11's Binary Edge: Up to 5.4x Smaller Than Boost.Python

Pybind11-generated C++ extension modules are typically at least 2x smaller than Boost.Python equivalents, with one large project reporting a 5.4x binary size reduction, largely due to its header-only design and minimal dependencies.

The top 3

  1. Pybind11's Header-Only Design: Key to Leaner Binaries: Pybind11 achieves significantly smaller binary sizes by functioning as a header-only library with minimal external dependencies, unlike Boost.Python which integrates the much larger Boost ecosystem. Its modern C++ design further reduces boilerplate code.
  2. PyRosetta Case: 5.4x Smaller Binary, 5.8x Faster Compile: A real-world conversion of the large PyRosetta project from Boost.Python to pybind11 demonstrated significant efficiency gains, resulting in a 5.4 times reduction in binary size and a 5.8 times faster compilation time.
  3. Beyond Size: Faster Builds, Easier Deployment: Pybind11's smaller binary size translates into practical advantages like reduced memory footprint per compilation unit, faster incremental builds, and simplified deployment processes for Python C++ extensions. Newer tools like nanobind are pushing these optimization boundaries even further.

Sources

Open the full topic