pythonnuitka

How to use Nuitka to compile jsonpickle (a Python lib) to C/C++?


I'm using jsonpickle in my program, but found it to be a performance bottleneck. So I'm trying to see if I can compile it to C using Nuitka, then use the C version in my program (through some wrappers perhaps).

But to be honest, I'm new to Nuitka, so I don't even know if this is a legit use case. Can someone give me some hints?

Note: this question is not about how to make a program faster. I'm building a library, not an application, so certain approaches like Pypy won't work. I'm also aware of Cython and is investigating it too, but this question is not about Cython either.


Solution

  • Figured it out myself. Just git clone the repo, go into the directory, and run

    python -m nuitka --module jsonpickle --include-package=jsonpickle
    

    Nuitka will generate a .so file, and you can import and use it just like the original package.

    This method should be universal and could apply to any package and not just jsonpickle.

    Do note that Nuitka is meant to be used in an application, but not good for building a library. The main pain point is that it doesn't support cross-compilation.