-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Speed up Path.iter_segments() #13039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
dcb5fbb
to
a798344
Compare
With the performance improvements in matplotlib#13040 and matplotlib#13039 the old slow path is now faster than the previously fast one. And it also works with pycairo.
Welcome to matplotlib development and thanks for your contribution. Comparing different types costs extra time as the following tests show: native (int, np.int64)
int reference, np.uint8 array:
np.uint8 reference, np.uint8 array:
np.uint64 reference, np.uint64 array:
|
Using the Gtk3Cairo backend with wire3d_animation_sgskip.py: Before: 9.16 fps After: 9.95 fps The main speedup is from iterating and keeping the common non-curve case simple.
Thanks for the benchmarks, using uint8 seems much faster indeed. Small question, do you mean adjusting Path.STOP, or only casting it in iter_segments(). The former would make many things using the constants faster everywhere I guess, but I'm not sure regarding compatibility. edit: I've pushed the direct change for starters. |
a798344
to
ce7a6a6
Compare
Yes, I meant the direct change. I'm 99% sure about compatibility. We should probably add an API change note to be on the safe side. That said, I'd still want the opinion of other devs on this. |
… the codes array The matching types make comparisons between the constants and values of the codes array faster. Using the Gtk3Cairo backend with wire3d_animation_sgskip.py: Before: 9.95 fps After: 15.26 fps The main areas where this helps for the cairo case is the faster comparisons in Path.iter_segments() and in _append_paths() of the cairo backend.
ce7a6a6
to
3b8689a
Compare
I've added something to next_api_changes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Out of curiosity, have you benchmarked the new version?
Only using wire3d_animation_sgskip + pycairo, see the PR summary and commits. (best out of 5 each time) |
With the performance improvements in matplotlib#13039 the old slow path is now faster than the previously fast one. And it also works with pycairo. Using the Gtk3Cairo backend with wire3d_animation_sgskip.py: cairocffi + append_fast: 13.27 fps cairo + append_slow: 15.07 fps cairocffi + append_slow: 13.54 fps
PR Summary
Using the Gtk3Cairo backend with wire3d_animation_sgskip.py:
before: 9.16 fps
iter: 9.95 fps
iter+types: 15.26 fps
The main speedup comes from iterating and keeping the common non-curve
case simple and from converting the code type constants to the same type as the codes array to make comparisons between them faster.
PR Checklist