Skip to content

[mypyc] Use native calls in singledispatch dispatch functions #10888

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

Merged
merged 2 commits into from
Jul 29, 2021

Conversation

pranavrajpal
Copy link
Contributor

This adds support for using native calls to registered implementations when generating dispatch functions for singledispatch functions, instead of always using non-native calls, which can significantly speed up singledispatch (see benchmark results below). We don't use native calls when the registered implementation is a decorated function, as using a native call would ignore any changes the decorator made to the function.

Benchmark Results

These are the results from running the sum_tree_singledispatch both with this change and on the current master (7808e82).

Current master

interpreted: 0.694200s (avg of 5 iterations; stdev 1%)
compiled:    0.661199s (avg of 5 iterations; stdev 1.3%)

compiled is 1.050x faster

This PR

interpreted: 0.701401s (avg of 5 iterations; stdev 1.4%)
compiled:    0.603199s (avg of 5 iterations; stdev 1.7%)

compiled is 1.163x faster

Test Plan

I added an irbuild test to make sure we are actually using native calls when there are no non-register decorators.

When generating calls to registered implementations in the dispatch
function for a singledispatch function, use a native call instead of a
non-native call to registered implementations to make dispatching
faster.

We still use non-native calls when the registered function has
non-register decorators, as using a native call in that case would cause
us to call the function without any modifications that the decorator
might do.
Add a singledispatch irbuild test to make sure that we actually use
native calls to registered implementations when they don't have any
non-register decorators, instead of using a non-native call.
Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

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

Looks great!

@msullivan msullivan merged commit a54a177 into python:master Jul 29, 2021
sthagen added a commit to sthagen/python-mypy that referenced this pull request Jul 29, 2021
[mypyc] Use native calls in singledispatch dispatch functions (python#10888)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants