Skip to content

PERF: Refactor bezier poly coefficient calcs for speedup#31059

Merged
QuLogic merged 2 commits into
matplotlib:mainfrom
scottshambaugh:bezier_coeffs
Feb 3, 2026
Merged

PERF: Refactor bezier poly coefficient calcs for speedup#31059
QuLogic merged 2 commits into
matplotlib:mainfrom
scottshambaugh:bezier_coeffs

Conversation

@scottshambaugh
Copy link
Copy Markdown
Contributor

@scottshambaugh scottshambaugh commented Feb 2, 2026

PR summary

Split off from #31005

This speeds up Path.get_extents which calls these bezier operations by caching more of the polynomial coefficient calculations. These repeated calcs were taking up about 25% of the get_extents call time, and are largely eliminated now.

Circled areas in the profiler screenshots below show this code path.

Before:
image

After:
image

Profiling test script:

import numpy as np
import matplotlib.pyplot as plt

fig, ax = plt.subplots()

n = 1000
rng = np.random.default_rng(42)
x = rng.random(n)
y = rng.random(n)
for i in range(n):
    ax.scatter(x[i], y[i])

fig.canvas.draw()
plt.close(fig)

PR checklist

@scottshambaugh scottshambaugh marked this pull request as ready for review February 2, 2026 18:57
Comment thread lib/matplotlib/bezier.py Outdated
Comment thread lib/matplotlib/bezier.py Outdated
@QuLogic QuLogic merged commit 9a41623 into matplotlib:main Feb 3, 2026
37 of 40 checks passed
@QuLogic QuLogic added this to the v3.11.0 milestone Feb 3, 2026
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.

3 participants