ITK icon indicating copy to clipboard operation
ITK copied to clipboard

Investigate migration from SWIG to nanobind

Open thewtex opened this issue 2 years ago • 1 comments

Description

Investigate migration from SWIG for Native Python to nanobind.

From its documentation:

More concretely, benchmarks show up to ~4× faster compile time, ~5× smaller binaries, and ~10× lower runtime overheads compared to pybind11. nanobind also outperforms Cython in important metrics (3-12× binary size reduction, 1.6-4× compilation time reduction, similar runtime performance).

Compile time, binary size, and runtime overhead are all very important issues for ITK. And, SWIG, the current wrapper, is likely worse than pybind11 and Cython already in these regards.

Also, nanobind has good support for scikit-build and Python 3 stable ABI -- we will be able to easily support as many platforms as possible while only needing to create 1 wheel per platform versus individual wheels per Python version.

thewtex avatar Jul 21 '23 20:07 thewtex

I can highly recommend nanobind. We are moving ANTsPy from pybind11 to nanobind and it has greatly reduced build time / size and sped up import time. The main downside is having to manually specify all of the image pixeltype + dimension combinations when wrapping the functions... but that's mostly copy-paste.

I think the time it currently takes to import the itk python package every time you start a python terminal and the wait to use certain functions for the first time are almost prohibitively long. Nanobind would help there.

ncullen93 avatar Apr 18 '24 20:04 ncullen93