Reusing the args tuple for PyCFunction calls? #416
Replies: 4 comments 5 replies
-
What happens if
? |
Beta Was this translation helpful? Give feedback.
-
Sorry, I just noticed that A better example would be calls to any C function/type that still doesn't support vectorcall (PyCFunction and PyCFunctionWithKeywords). |
Beta Was this translation helpful? Give feedback.
-
Ultimately we want to use a more efficient interface, #374. In the short to medium term, the cache of tuples could work, but where would it live? |
Beta Was this translation helpful? Give feedback.
-
I guess the refcnt check will handle recursive calls and calls from multiple threads at once? I'm not sure how this would interact with nogil but we'll have to cross that bridge when we get to it. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I noticed
this call doesn't specialize because json.loads iscalls withMETH_VARARGS
(aka PyCFunction) andPyCFunctionWithKeywords
don't specialize.Specializing for that isn't going to give us a large speedup (if any at all) because the temporary args tuple still needs to be constructed at every call. The args tuple is then usually deallocated after the call.
What if:
At compile time, we find the call with the most number of arguments in the code object, then pre-allocate an empty tuple of that size and attach it to the code object.
At runtime, we re-use this preallocated tuple object on every call, avoiding most tuple allocations (maybe?).
Has anyone tried this before and found that it speeds up anything? In theory, this should make non-vectorcall calls nearly as fast as vectorcall.
Note:
We should not apply this to calls to python functions because it's already done with how inlined Python call frames currently work in the
CALL
instruction.Edit:
I removed my rambling about
json.load
because it was inaccurate. See this comment.Beta Was this translation helpful? Give feedback.
All reactions