X Tutup
The Wayback Machine - https://web.archive.org/web/20240829110437/https://github.com/python/cpython/issues/123372
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

Python reports vectorcall as available even when using it will not help and even hurt performance #123372

Open
ChayimFriedman2 opened this issue Aug 27, 2024 · 0 comments
Labels
performance Performance or resource usage topic-C-API type-bug An unexpected behavior, bug, or error

Comments

@ChayimFriedman2
Copy link

ChayimFriedman2 commented Aug 27, 2024

Bug report

Bug description:

The following Python function

def foo(*args): pass

Has vectorcall enabled (PyVectorcall_Function() returns a non-NULL function), but because it collects args, Python needs to convert the arguments into a tuple, and so vectorcall won't be any faster than allocating a tuple directly.

This is not a problem if we know the number of arguments beforehand, but if we allocate the array for vectorcall, we will allocate twice needlessly.

Avoiding allocating for vectorcall also does not always provide the best performance, because vectorcall can have an edge with bound methods with the flag PY_VECTORCALL_ARGUMENTS_OFFSET.

Per the docs:

A class should not implement vectorcall if that would be slower than tp_call. For example, if the callee needs to convert the arguments to an args tuple and kwargs dict anyway, then there is no point in implementing vectorcall.

As such, I believe this function (and similar functions) should not implement vectorcall.

Originally reported on Stack Overflow.

CPython versions tested on:

3.12

Operating systems tested on:

Windows

@ChayimFriedman2 ChayimFriedman2 added the type-bug An unexpected behavior, bug, or error label Aug 27, 2024
@python python deleted a comment Aug 27, 2024
@python python deleted a comment Aug 27, 2024
@python python deleted a comment Aug 27, 2024
@python python deleted a comment Aug 27, 2024
@python python deleted a comment Aug 27, 2024
@python python deleted a comment Aug 27, 2024
@mdboom mdboom added the performance Performance or resource usage label Aug 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage topic-C-API type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants
X Tutup