You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Build pyopenms against the python limited/stable ABI if possible #8185
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
We should revisit this with nanobind. I remember in Cython there were some smaller caveats including a little bit of performance impacts.
We should check what the state for nanobind is and consider it. Would reduce number of builds and wheels to ship significantly.
Following up on @jpfeuffer's suggestion to revisit this with nanobind — here's a research summary.
nanobind supports stable ABI natively
nanobind provides a STABLE_ABI flag on nanobind_add_module(), requiring Python 3.12+. Once enabled, extensions get the .abi3.so suffix and a single wheel works across Python minor versions.
Current pyOpenMS compatibility is high
All 13 bind_*.cpp files use zero direct CPython C API — they're pure nanobind abstractions and need no changes
arrow_zerocopy.cpp also uses only nanobind abstractions — no changes needed
The only files needing changes are 5 type caster headers in bindings/type_casters/
CPython API usage in type casters is mostly stable-ABI-compatible
The initial concern was ~248 direct CPython C API calls across the type casters. However, most functions used (PyList_New, PyDict_New, PySequence_GetItem, PyUnicode_AsUTF8AndSize, Py_DECREF, PyXxx_Check, etc.) are all part of the stable ABI as of Python 3.12.
The only real incompatibility found:
PyList_SET_ITEM() (~8 occurrences) → must be replaced with PyList_SetItem() (stable ABI equivalent, also steals references)
Trade-offs
Factor
Impact
Minimum Python version
Rises from 3.10 → 3.12
Wheel builds
1 per platform instead of 1 per Python version (5→1)
Performance
Small cost — nanobind can no longer access CPython struct internals directly
Code changes
~8 PyList_SET_ITEM → PyList_SetItem replacements in type casters + CMake flag additions
Vectorcall limitations on Python < 3.14 under stable ABI (minor)
Open question
Is dropping Python 3.10/3.11 acceptable? Two options:
(a) Raise minimum to 3.12, ship only abi3 wheels (max benefit, simplest)
(b) Hybrid: abi3 wheels for 3.12+, version-specific wheels for 3.10/3.11 (reduces builds from 5 to 3)
Estimated effort
This is a relatively small change — primarily adding STABLE_ABI to the ~13 nanobind_add_module() calls in CMake and replacing 8 macro calls in type casters. The NB_DOMAIN "pyopenms" cross-module type sharing should work with stable ABI as nanobind handles this internally. Testing across Python versions would be the main effort.
Ran benchmarks sequentially (10 repeats each) on the same machine, comparing non-abi3 vs abi3 builds. Branch: feature/stable-abi-pyopenms.
Summary
Overall mean delta: +12.0% — in the yellow zone (5-15% threshold).
The regression is not in our code changes (type casters, CMake flags). It's in nanobind's per-call dispatch overhead under stable ABI — every Python→C++ call goes through an indirection layer.
Results by category
Category
Delta
Verdict
Type Casters (our custom casters: DataValue, String, STL)
-18% to -30% (faster)
PASS
Type Conversions (getMetaValue, getNativeID, etc.)
Our PyList_SET_ITEM → PyList_SetItem changes have zero negative impact. Type caster round-trips are actually faster under abi3.
The regression is entirely in nanobind's per-call dispatch. Operations that make many small Python→C++ calls (constructing 10k objects, per-element __getitem__, Arrow export which iterates per-spectrum) see 25-50% overhead.
Bulk operations are unaffected. DataFrame exports, large rasterizations, and zero-copy memory views show no regression — the time is spent in C++, not in the binding layer.
Arrow export regression (~25%) is because the C++ Arrow bridge makes per-spectrum calls through nanobind. The Python-side to_df() wrapper (which does bulk work) is unaffected.
Recommendation
This is a yellow light result — the overhead is real but concentrated in micro-benchmarks that stress the binding layer. Real-world pyOpenMS workloads that load files, process spectra in bulk, and export DataFrames would see minimal impact. The main pain point is Arrow export (~25% slower) and tight loops constructing many small objects.
Options:
(A) Accept the overhead — the type caster paths (our main concern) are fine, and bulk operations are unaffected. The 25-50% per-call overhead is a known stable ABI trade-off.
(B) Wait for nanobind improvements — nanobind is actively improving stable ABI performance (vectorcall on 3.14+, etc.). Re-evaluate after nanobind 2.11+.
(C) Hybrid approach — only enable stable ABI on platforms where wheel count is most painful (e.g., Linux), keep full ABI on others.
Environment
Python 3.12.3, nanobind 2.10.0, Linux (WSL2)
10 repeats per benchmark, sequential execution
Full results: [compare_benchmarks.py output above]
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Resolved on develop (verified @ c5403a8) — pyOpenMS does build against the stable ABI now, so the "build for 5 py versions all the time" problem this issue was about is gone.
src/pyOpenMS/CMakeLists.txt:44 defines PYOPENMS_SPLIT_MODE ("Build stable-ABI (abi3) extensions in nanobind split mode"), default ON; CMake turns STABLE_ABI_VERSION into Py_LIMITED_API and py-build-cmake turns abi3_minimum_cpython_version into the wheel's cp<N>-abi3 tag (:47-55), with a guard against packaging a non-abi3 local build as abi3.
The published nightlies match: one cp311-abi3 wheel per platform, covering CPython 3.11+.
Note this went via nanobind rather than the Cython limited-API route the issue links to, so the wontfix label no longer reflects the state. Proposing to close.
Activity
github-actions commentedon Feb 22, 2026
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
jpfeuffer commentedon Mar 10, 2026
We should revisit this with nanobind. I remember in Cython there were some smaller caveats including a little bit of performance impacts.
We should check what the state for nanobind is and consider it. Would reduce number of builds and wheels to ship significantly.
timosachsenberg commentedon Mar 16, 2026
Stable ABI Feasibility Analysis (nanobind)
Following up on @jpfeuffer's suggestion to revisit this with nanobind — here's a research summary.
nanobind supports stable ABI natively
nanobind provides a
STABLE_ABIflag onnanobind_add_module(), requiring Python 3.12+. Once enabled, extensions get the.abi3.sosuffix and a single wheel works across Python minor versions.Current pyOpenMS compatibility is high
bind_*.cppfiles use zero direct CPython C API — they're pure nanobind abstractions and need no changesarrow_zerocopy.cppalso uses only nanobind abstractions — no changes neededbindings/type_casters/CPython API usage in type casters is mostly stable-ABI-compatible
The initial concern was ~248 direct CPython C API calls across the type casters. However, most functions used (
PyList_New,PyDict_New,PySequence_GetItem,PyUnicode_AsUTF8AndSize,Py_DECREF,PyXxx_Check, etc.) are all part of the stable ABI as of Python 3.12.The only real incompatibility found:
PyList_SET_ITEM()(~8 occurrences) → must be replaced withPyList_SetItem()(stable ABI equivalent, also steals references)Trade-offs
PyList_SET_ITEM→PyList_SetItemreplacements in type casters + CMake flag additionsOpen question
Is dropping Python 3.10/3.11 acceptable? Two options:
Estimated effort
This is a relatively small change — primarily adding
STABLE_ABIto the ~13nanobind_add_module()calls in CMake and replacing 8 macro calls in type casters. TheNB_DOMAIN "pyopenms"cross-module type sharing should work with stable ABI as nanobind handles this internally. Testing across Python versions would be the main effort.jpfeuffer commentedon Mar 16, 2026
What about performance? I know in Cython enabling this comes with some performance hits since it cannot optimize for certain python versions.
jpfeuffer commentedon Mar 16, 2026
Ah here:
timosachsenberg commentedon Mar 16, 2026
I can try to add a benchmark.
timosachsenberg commentedon Mar 16, 2026
how to handle conda? there we need to build from scratch right?
jpfeuffer commentedon Mar 16, 2026
https://conda-forge.org/docs/maintainer/knowledge_base/#packages-with-abi3-extensions
timosachsenberg commentedon Mar 16, 2026
Stable ABI Benchmark Results
Ran benchmarks sequentially (10 repeats each) on the same machine, comparing non-abi3 vs abi3 builds. Branch:
feature/stable-abi-pyopenms.Summary
Overall mean delta: +12.0% — in the yellow zone (5-15% threshold).
The regression is not in our code changes (type casters, CMake flags). It's in nanobind's per-call dispatch overhead under stable ABI — every Python→C++ call goes through an indirection layer.
Results by category
__getitem__, push_back)Key observations
Our
PyList_SET_ITEM→PyList_SetItemchanges have zero negative impact. Type caster round-trips are actually faster under abi3.The regression is entirely in nanobind's per-call dispatch. Operations that make many small Python→C++ calls (constructing 10k objects, per-element
__getitem__, Arrow export which iterates per-spectrum) see 25-50% overhead.Bulk operations are unaffected. DataFrame exports, large rasterizations, and zero-copy memory views show no regression — the time is spent in C++, not in the binding layer.
Arrow export regression (~25%) is because the C++ Arrow bridge makes per-spectrum calls through nanobind. The Python-side
to_df()wrapper (which does bulk work) is unaffected.Recommendation
This is a yellow light result — the overhead is real but concentrated in micro-benchmarks that stress the binding layer. Real-world pyOpenMS workloads that load files, process spectra in bulk, and export DataFrames would see minimal impact. The main pain point is Arrow export (~25% slower) and tight loops constructing many small objects.
Options:
Environment
docs: add stable ABI migration design spec for pyOpenMS
fix: replace PyList_SET_ITEM with PyList_SetItem for stable ABI compat
feat: enable Python Stable ABI (abi3) for pyOpenMS nanobind modules
feat: update Python version requirements to 3.12+ for stable ABI
ci: split build/test matrix for abi3 wheels
jpfeuffer commentedon Mar 16, 2026
Yes. I expected that pattern. It is more significant than I thought. Maybe caching is better?
timosachsenberg commentedon Mar 16, 2026
Maybe it is not that bad. A bit hard to benchmark though… will try again.
github-actions commentedon Sep 13, 2026
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
[FEATURE] pyOpenMS: opt-in PYOPENMS_STABLE_ABI build against the Pyth…
[FIX] pyOpenMS: keep PyList_SET_ITEM outside limited-API builds; stab…
timosachsenberg commentedon Sep 21, 2026
Resolved on
develop(verified @c5403a8) — pyOpenMS does build against the stable ABI now, so the "build for 5 py versions all the time" problem this issue was about is gone.src/pyOpenMS/CMakeLists.txt:44definesPYOPENMS_SPLIT_MODE("Build stable-ABI (abi3) extensions in nanobind split mode"), default ON; CMake turnsSTABLE_ABI_VERSIONintoPy_LIMITED_APIand py-build-cmake turnsabi3_minimum_cpython_versioninto the wheel'scp<N>-abi3tag (:47-55), with a guard against packaging a non-abi3 local build as abi3.The published nightlies match: one
cp311-abi3wheel per platform, covering CPython 3.11+.Note this went via nanobind rather than the Cython limited-API route the issue links to, so the
wontfixlabel no longer reflects the state. Proposing to close.Generated by Claude Code