FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Draft: Experiment with using nanobind by iccir · Pull Request #32411 · matplotlib/matplotlib · GitHub

Repository navigation

Draft: Experiment with using nanobind - #32411

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

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

Conversation

iccir commented Sep 29, 2026 •
edited
Loading

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

# 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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I pulled this out into #32417

iccir added 2 commits October 3, 2026 10:18
Accept arrays of any shape so we can do our own validation and provide better error messages. This restores most of the test_triangulation test suite to the pre-nanobind version.

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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


Back | FazBrowse Home | New Git URL