Repository navigation
Open
Labels
performancePerformance or resource usagePerformance or resource usagetopic-argument-clinictype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
Description
Feature or enhancement
Argument Clinic can now generate vectorcall for class __init__ and __new__ (gh-87613). This is a meta tracking issue for moving objects to use Argument Clinic generated Vectorcall for these cases:
- Replacing a handwritten vectorcall with the same behavior and equal or better performance.
- Minor changes in exception text for bad arguments are okay
- Replacing
PyArg_Parse*with Argument Clinic + Vectorcall- At least a 10% performance boost in pyperf microbenchmark.
- Minor changes in exception text for bad arguments are okay
- Adding Vectorcall to objects which currently use Argument Clinic but do not support it
- For these one of the following should apply:
- The objects are common in performance critical code. This should generally be shown with an improvement on a
pyperformancebenchmark. If it's critical for a real application but there are no benchmarks, we should add them. - Speedup is substantial: over 15% in microbenchmarks. If the operation is a small part of a larger common operation (ex.
json.Encoderinjson.dumps), that operation must improve by at least 5% on a typical input. This is because vectorcall adds significant code for the performance it enables.
- The objects are common in performance critical code. This should generally be shown with an improvement on a
- For these one of the following should apply:
For all the cases it's important to validate
- Behavior is the same across a wide range of inputs. Changes must be documented and noted. Substantial chagnes mean a different issue from this one is required.
- There are no regressions for specific argument patterns.
tp_callkeeps strong references in the argument tuple. In vectorcall the arguments are borrowed references. Make sure to hold a strong reference (Py_INCREF) before calling arbitrary Python code.
If new features are neededed those should be worked on in other issues. Ideally don't want to both convert a type and change existing codegen in one PR. Issues with AC Vectorcall code generation should be reported in gh-87613.
Good Candidates
-
itertools -
operator:itemgetter,attrgetter -
types:MethodType(gh-162350: Add AC vectorcall for method.__new__ to speed up types.MethodType #162408),CellType,FrameLocalsProxy,MappingProxyType,FunctionType -
memoryview -
property -
sentinel -
string.templatelib:Template,Interpolation -
typing:TypeAliasType,ParamSpecArgs,ParamSpecKwargs -
pickle.PickleBuffer -
contextvars.ContextVar -
array.array- gh-162350: Use AC for array.array constructor #162419 -
csv -
datetime:timezone,timedelta -
zoneinfo -
queue.SimpleQueue -
io.IncrementalNewlineDecoder -
ctypes.CField -
map -
json- gh-162350: Use AC vectorcall for _json.make_encoder to speed up json.dumps #162376 -
complex- gh-162350: Use AC vectorcall for complex() #162417
Blocked: Require known feature work
- gh-87613: Supprt **kwargs in AC VC and use for xml.etree.ElementTree.Element #161597: Support
**kwargsin AC vectorcallcollections.defaultdict,operator.methodcaller,functools.partial,objectcollections.OrderedDict(also needs the self cast fix)- Exception hierarchy
asyncio.Task,asyncio.Futurexml.etree.ElementTree
- Other known improvements needed
-
set,frozenset -
super -
sqlite3.Cursor,sqlite3.Row -
datetime.date,datetime.time,datetime.datetime
-
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
- gh-162350: Use AC vectorcall for _json.make_encoder to speed up json.dumps #162376
- gh-162350: Add AC vectorcall for method.__new__ to speed up types.MethodType #162408
- gh-162350: Use AC vectorcall for complex() #162417
- gh-162350: Use AC for array.array constructor #162419
- gh-162350: Use AC vectorcall for cell.__new__ to speed up types.CellType #162422
- gh-162350: Use AC vectorcall for framelocalsproxy_new to speed up types.FrameLocalsProxyType #162424
- gh-162350: Add AC vectorcall for mappingproxy.__new__ to speed up types.MappingProxyType #162430
- gh-162350: Add AC vectorcall for function.__new__ to speed up types.FunctionType #162433
- gh-162350: Add AC @vectorcall for asyncio module objects #162439
- gh-162350: Add AC vectorcall for memoryview, property, sentinel, and typing #162440
- gh-162350: Add AC vectorcall for pickle.PickleBuffer #162448
- gh-162350: Add AC vectorcall for contextvars.ContextVar #162451
- gh-162350: Add AC vectorcall for string.templatelib #162452
Metadata
Metadata
Assignees
Labels
performancePerformance or resource usagePerformance or resource usagetopic-argument-clinictype-refactorCode refactoring (with no changes in behavior)Code refactoring (with no changes in behavior)
Activity
skirpichev commentedon Nov 21, 2026
As I mentioned before, probably it's impossible. Or you did it in your draft branch, mentioned in this pr?
cmaloney commentedon Nov 21, 2026
I'd forgotten about that thread. There are some existing AC hooks to handle cases like that. I really want to teach Argument Clinic about "overloads" of functions... are a lot of cases such as that one I think would do well as "this exact signature + types" (complex keyword only being one) -> "this C Implementation function". I've prototyped that some and if that info is made available as a C API disaptch table the specializing adaptive interpreter can get to sizable performance improvements.
cmaloney commentedon Nov 21, 2026
Investigated a bit more, can detect the "real as keyword arg" vs. "real as positional" using
real_pos, imag_pos, /, *, real, imagwhile keeping the same visible signature (@text_signature "(real=0, imag=0)"). That letsreal_posvsrealkeyword have different handling without anything new.gh-162350: Add AC vectorcall for method.__new__ to speed up types.Met…
gh-162350: Add AC @vectorcall for asyncio module objects (#162439)
gh-162350: Use AC vectorcall for framelocalsproxy_new to speed up typ…
gh-162350: Use AC vectorcall for cell.__new__ to speed up types.CellT…
gh-162350: Add AC vectorcall for mappingproxy.__new__ to speed up typ…