[Python] Long import time of pybind11 extension

Discussão em 'Python' iniciado por Stack, Maio 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have a C++ library with a Python interface, generated using pybind11. The library is compiled into a single shared object kernel.so, with 29MB of size. Importing the module from a Python script takes about 7 seconds, which makes using it annoying.

    I am assuming that the reason for this is simply the size of the module, but I don't have a reference for how big modules generally are or how long should it take to load a module of this size, so I could perfectly be wrong.

    Is there a way for me to profile an import from a shared library? Any suggestion of tools that could allow me to examine the kernel.so to understand why it has the size it has would also be really appreciated. So far, I have tried nm and objdump, but I haven't managed to get anything useful out of them.

    NOTE: I have already tried to split the library into multiple shared objects, but I cannot do it without refactoring code due to compiler-dependent RTTI.

    Continue reading...

Compartilhe esta Página