-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Avoid temporary varargs
tuple creation in argument passing
#90370
Comments
When "Augument Clinic generated code" are parsing arguments, the args are packed to a tuple before passing to callee. This may be unnecessary. Pass a raw pointer which points to on-stack varargs, and a varargssize integer to indicate how many varargs are passed, can save the time of tuple creation/destruction and value copy. |
I wrote some microbenchs. Patch: b68176d Environment: Result on microbench:
|
Note that _PyArg_UnpackKeywordsWithVararg is defined with PyAPI_FUNC. Changing its argument spec is strictly a backwards incompatible change, IIUC. |
I am a rookie in Python, did not notice changing PyAPI_FUNC means breaking backward compatibility. I have reverted _PyArg_UnpackKeywordsWithVararg and committed again. |
AFAIK we have committed _PyArg_UnpackKeywordsWithVararg on 3.11 alpha, so I think it should be fine. Also CC: @pablogsal |
I see, so no ABI worries then. |
It seems #30312 was abandoned by author. I'll continue this work. |
Current patch partially address issue, working in case when all arguments either positional-only or vararg. This also converts gcd(), lcm() and hypot() functions of the math module to the Argument Clinic. Fix issue python#101123. Objects/setobject.c and Modules/gcmodule.c adapted. This fixes slight performance regression for set methods, introduced by python#115112: | Benchmark | ref | patch | |----------------------|:------:|:--------------------:| | set().update(s1, s2) | 354 ns | 264 ns: 1.34x faster | Benchmark code: ```py import pyperf s1, s2 = {1}, {2} runner = pyperf.Runner() runner.bench_func('set().update(s1, s2)', set().update, s1, s2) ```
#126064 is ready for review (partially address issue) |
@erlend-aasland, I'm not sure we can mark this a fixed issue. The merged pr covers only part of the original proposal (e.g. it doesn't work for the OP example with print()). |
I planned to came to this issue in few steps:
There may be other intermediate steps. I tried to do this in one step, but it was too complicated. Now, #126064 created conflicts with #122945. I spent a day for this, and see a light at the end of tunnel, but the simplest way to resolve conflict is to revert #126064. Then merge #122945, then continue the initial plan. This will take a time. Alternatively, I can fuse all these steps in #122945, but the result will be larger and very dirty, because I would need to use dirty tricks like using globals to pass values of local variables between function calls in three or four different modules. |
Reverting #126064 will also mean reverting #126235. Are there any others that would need reverting, @skirpichev? |
Not necessary. Reverting #126064 will just introduce some performance regression for converted functions. But as @serhiy-storchaka planned to address this issue In The Right Way - this will be eventually fixed.
None, as far as I know. |
Sounds good. Serhiy, please go ahead. |
(Given the size (few lines) of #126064, I don't see big problem to resolve merge conflicts. I'll try to do this. Serhiy, feel free to ignore these efforts.) |
IMO, this would be the best option; if we can avoid the revert churn that would be great. |
So, if this is not urgent, give me a day. |
Thanks, @colorfulappl, for the proposal and initial work; thanks Serhiy and Sergey for the PRs 🍰 👏 🥳 |
…arargs (python#126064) Avoid temporary tuple creation when all arguments either positional-only or vararg. Objects/setobject.c and Modules/gcmodule.c adapted. This fixes slight performance regression for set methods, introduced by pythongh-115112.
…arargs (python#126064) Avoid temporary tuple creation when all arguments either positional-only or vararg. Objects/setobject.c and Modules/gcmodule.c adapted. This fixes slight performance regression for set methods, introduced by pythongh-115112.
varargs
tuple creation in argument passing #30312Note: 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:
Linked PRs
The text was updated successfully, but these errors were encountered: