You have a Python codebase. Thousands of lines. It works. Your team knows it. Your tests cover it. Your CI/CD deploys it.
But there’s this one function. It shows up in every profile. It’s eating 80% of your runtime. You know it would be faster in C++.
The traditional answer? Rewrite it in C++, then spend sometime writing pybind11 boilerplate to call it from Python. Or just… don’t bother.
Mirror Bridge is a third option: write C++, run one command, done.
The Setup
Let’s say you have a simple operation - a dot product:
// vec3.hpp struct Vec3 { double x , y , z ; Vec3 ( double x , double y , double z ) : x ( x ), y ( y ), z ( z ) {} double dot ( const Vec3 & other ) const { return x * other . x + y * other . y + z * other . z ; } // Compute the magnitude (norm) of the vector double length () const { return std :: sqrt ( x * x + y * y + z * z ); } };
To use this from Python:
./mirror_bridge_auto src/ --module vec3 -o .
That’s it. No binding code. Mirror Bridge uses C++26 reflection to discover your classes, methods, and fields automatically.
... continue reading