Improving Python/C/C++ and general development process

I’ve been following this discussion a bit, but the above kind of sums up the Python vs C++ debate for me. Experienced programmers will (of course) be able to learn C++. But while someone who has never coded has a good change of being able to pick up Python, C++ is simply a step too far as a first language. Your prior programming experience matters at lot. The current Python API is fairly easy to get into, once you get used to all the quirks, which makes it more accessible to a lot of people. And yes, don’t go to university to learn coding :wink:

Python performance is only bad when using pure Python to do all kinds of computations or data processing. The reason the importers are slow is that they do all parsing of text input in Python itself, instead of calling into a C/C++ library (like assimp) to do the heavy lifting. That’s why things like numpy exist, Python merely becomes the glue for specifying the high-level operations, the actual number crunching work is done outside of Python.

Having a C++ API would only make it somewhat easier to couple C/C++ code to Blender. The current Python API already allows that, cf. the comments on Cython earlier. Plus, if you know what you’re doing (i.e. experienced C++ programmers) you can use pybind11 or Boost.Python to create a Python module for a piece of C++ that is fast but can also be called from a Blender Python script.

But I think there’s currently a few things suboptimal in the Python API when it comes the above:

  • Integration with the Python buffer protocol isn’t fully there, so passing large chunks of data (which should be a cheap pointer copy) is sometimes very slow as the data itself is copied. This hurts the overall performance of the Python API. See Pass a render result as a numpy array to bpy.types.RenderEngine posted today, or Bpy.data.images perf issues. These’s even a patch in the latter thread to vastly improve image copying performance.

  • Building a Python extension module that works with Blender is not as easy as it can be (e.g. the missing headers noted in Including Python headers in distribution? by myself, challenges in building the module, how to properly install new Python modules in Blender’s environment, etc.). Improving this might help in attracting C++ developers that can provide optimized modules for certain tasks without having to know the Blender C++ code itself. Merely having a good API (the current Python API) is enough. Case in point: my PLY importer for Blender, written in C using a C library, but available as a Python library. But turning this into a true add-on is then not that straightforward again, as it requires the user to compile the source (although I haven’t looked if there’s general instructions for distributing Blender add-ons containing system-specific binaries, like a Python module).