X Tutup
The Wayback Machine - https://web.archive.org/web/20210421213436/https://github.com/python/mypy/pull/9894
Skip to content
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

[mypyc] Use faster METH_FASTCALL wrapper functions on Python 3.7+ #9894

Merged
merged 23 commits into from Jan 23, 2021
Merged

Conversation

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jan 9, 2021

Implement faster argument parsing based on METH_FASTCALL on supported
Python versions.

Use vgetargskeywordsfast extracted from Python 3.9 with some modifications:

  • Support required keyword-only arguments, *args and **kwargs
  • Only support the 'O' type (to reduce code size and speed things up)

The modifications are very similar to what we have in the old-style
argument parsing logic.

The legacy calling convention is still used for __init__ and __call__. I'll add
__call__ support in a separate PR. I haven't looked into supporting __init__
yet.

Here are some benchmark results (on Python 3.8)

  • keyword_args_from_interpreted: 3.5x faster than before
  • positional_args_from_interpreted: 1.4x faster than before

However, the above benchmarks are still slower when compiled. I'll continue
working on further improvements after this PR.

Fixes mypyc/mypyc#578.

@JukkaL JukkaL requested a review from msullivan Jan 9, 2021
Copy link
Collaborator

@ilevkivskyi ilevkivskyi left a comment

LGTM, just one suggestion.

# This is because CPyArg_ParseStackAndKeywords format string requires
# them grouped in that way.
groups = make_arg_groups(real_args)
reordered_args = reorder_arg_groups(groups)

This comment has been minimized.

@ilevkivskyi

ilevkivskyi Jan 18, 2021
Collaborator

These preparatory steps here are very similar to the legacy wrapper below. Would it make sense to factor them out in a helper?

This comment has been minimized.

@JukkaL

JukkaL Jan 23, 2021
Author Collaborator

Refactored some of the shared code. I didn't share everything, since I'm planning further changes that may only be relevant for new-style wrapper functions.

@JukkaL JukkaL merged commit 5d2ea16 into master Jan 23, 2021
7 checks passed
7 checks passed
Comment
Details
Run (0)
Details
build (windows-py37-32)
Details
Run (1)
Details
build (windows-py37-64)
Details
Run (2)
Details
Travis CI - Pull Request Build Passed
Details
@JukkaL JukkaL deleted the vectorcall branch Jan 23, 2021
JukkaL added a commit that referenced this pull request Jan 23, 2021
Allocate a vectorcall function pointer as a struct field for native
classes that include `__call__`, including nested functions. This
lets us use METH_FASTCALL wrapper functions with `__call__`
methods.

See https://www.python.org/dev/peps/pep-0590/ for details of why
we jump through these hoops.

This makes the `nested_func` microbenchmark about 1.5x faster.

Follow-up to #9894.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants
X Tutup