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
Argument Clinic: improve generated parser for 1-argument functions #67680
Comments
Proposed patch improve generated parsers for functions with single positional argument. Now they always generated as METH_O and PyArg_Parse() is used to parse single argument. To avoid code churn in this and following changes it would be worth to extract all generated code in separated files. |
I'm not opposed to the patch in principle. I assume your goal is to make Python faster--do you have any data on how much faster? I don't support immediately changing all uses of Argument Clinic to generate their code into a separate file. I would want to see a consensus from the community first. Perhaps we should discuss it (again?) on python-dev? |
This is one step on long way. Second step will be to inline PyArg_Parse for |
Serhiy, I suggest you look at the code that Cython generates for its functions. It has been extensively profiled and optimised (years ago), so generating the same code for the argument clinic should yield the same performance. And while I don't have exact numbers at hand, avoiding the tuple packing for the call by passing it into a METH_O function can make a substantial difference. It also kills support for keyword arguments, though. |
Stefan: Serhiy's patch only affects functions taking a single positional-only parameter. |
lgtm |
Thanks, I'll look on it.
Good idea. Here are samples: $ ./python -m timeit "chr(0x20ac)"
Unpatched: 1000000 loops, best of 3: 0.976 usec per loop
Patched: 1000000 loops, best of 3: 0.752 usec per loop
$ ./python -m timeit -s "from cmath import isnan; x = 1j" -- "isnan(x)"
Unpatched: 1000000 loops, best of 3: 0.62 usec per loop
Patched: 1000000 loops, best of 3: 0.386 usec per loop Of course for more complex functions the effect is smaller. |
After expanding PyArg_Parse for "i" and "D" codes above tests give following results: $ ./python -m timeit "chr(0x20ac)"
1000000 loops, best of 3: 0.558 usec per loop
$ ./python -m timeit -s "from cmath import isnan; x = 1j" -- "isnan(x)"
1000000 loops, best of 3: 0.278 usec per loop About twice in comparison with initial variant! |
Let's make Argument Clinic a fierce optimizer! |
New changeset e10ad4d4d490 by Serhiy Storchaka in branch 'default': |
New changeset 973c9ec53bbb by Serhiy Storchaka in branch 'default': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: