Skip to content

Draft: Experiment with using nanobind - #32411

Draft
iccir wants to merge 16 commits into
matplotlib:mainfrom
iccir:nanobind-experiment
Draft

iccir wants to merge 16 commits 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 Δ
_backend_agg 535K
_c_internal_utils 190K 108K -82K
_image 355K
_path 355K
_qhull 571K 498K -73K
_tkagg 211K 126K -85K
_tri 321K 192K -129K
ft2font 2659K 2122K -537K

Compilation Time Comparison

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

Italics = preliminary results

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

# No triangulation specified, so use matplotlib._qhull to obtain
# Delaunay triangulation.
self.triangles, self._neighbors = _qhull.delaunay(x, y, sys.flags.verbose)
self.triangles, self._neighbors = _qhull.delaunay(self.x, self.y,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good catch. It is functionally identical but will be slightly faster in some circumstances so we should do it even if this PR is never merged.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled this out into #32417

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

None yet

Development

Successfully merging this pull request may close these issues.

2 participants