Skip to content

Draft: Experiment with using nanobind - #32411

Draft
iccir wants to merge 1 commit into
matplotlib:mainfrom
iccir:nanobind-experiment
Draft

iccir wants to merge 1 commit into
matplotlib:mainfrom
iccir:nanobind-experiment

Conversation

@iccir

@iccir iccir commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

PR summary

I'm tinkering with nanobind to re-acquaint myself with C++ after a 20+ year hiatus. This is a draft pull request so I can run CI on my experiments.

Results

Binary Size Comparison

(darwin, arm64)

Extension pybind11 nanobind Δ nanobind
(Split Mode)
Δ
(Split Mode)
_backend_agg 535K 339K -196K 266K -269K
_c_internal_utils 190K 108K -82K 53K -137K
_image 355K 257K -98K 166K -189K
_path 355K 225K -130K 153K -202K
_qhull 571K 498K -73K 426K -145K
_tkagg 211K 126K -85K 53K -158K
_tri 321K 192K -129K 103K -218K
ft2font 2659K 2122K -537K 2095K -564K
TOTAL 5197K 3867K -1330K 3315K -1882K

Results: ~1.33M saved per wheel by switching to nanobind and ~1.88M if we use Split Mode.

Note: Split Mode adds a dependency on nanobind-backend. This is an 80K-450K download depending on architecture and is shared amongst all projects in an environment that use nanobind split mode.

Compilation Time Comparison

Extension pybind11 nanobind
_backend_agg 5.605s 3.384s
_c_internal_utils 1.964s 1.177s
_image 3.932s 2.096s
_path 3.654s 1.970s
_qhull 3.946s 3.058s
_tkagg 2.139s 1.206s
_tri 3.157s 1.604s
ft2font 18.418s 15.532s

AI Disclosure

  • I use AI for web search due to search engines becoming less reliable.
  • I used AI to port small snippets of code from pybind to nanobind. I then took the same approach and manually ported sections myself.
  • I used AI for help with the C++ STL.

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • [/] New and changed code is tested
  • [/] Plotting related features are demonstrated in an example
  • [/] New features and API changes have release notes
  • [/] Documentation complies with general and docstring guidelines

Comment thread lib/matplotlib/tri/_triangulation.py Resolved
@iccir
iccir force-pushed the nanobind-experiment branch from 2ab85f1 to bf5ec18 Compare November 12, 2026 04:51
@github-actions github-actions Bot added the CI: Run cibuildwheel Run wheel building tests on a PR label Nov 12, 2026
@iccir iccir added this to nanobind Nov 13, 2026
@github-project-automation github-project-automation Bot moved this to Todo in nanobind Nov 13, 2026
@iccir iccir moved this from Todo to N/A in nanobind Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: N/A

Development

Successfully merging this pull request may close these issues.

2 participants