[Python-ideas] Bytecode for calling function with keyword arguments

Serhiy Storchaka storchaka at gmail.com
Sat Apr 23 07:14:30 EDT 2016


On 21.04.16 20:28, Serhiy Storchaka wrote:
> On 21.04.16 19:00, Chris Angelico wrote:
>> Also: How does this interact with **dict calls?
>
> For now we have separate opcode for calls with **kwargs. We will have
> corresponding opcode with new way to provide keyword arguments.
>
> Instead of 4 current opcodes we will need at most 8 new opcodes. May be
> less, because calls with *args or **kwargs is less performance critical,
> we can pack arguments in a tuple and a dict by separate opcodes and call
> a function just with a tuple and a dict.

Actually I think we need only 3 opcodes: one general and two specialized 
for common cases.

1. Call with fixed number of positional arguments. This covers about 90% 
of calls.

2. Call with fixed number of positional and keyword arguments. This 
covers about 10% of calls.

3. Call with variable number of positional and/or keyword arguments 
packed in a tuple and a dict. Only 0.5% of calls need this. Since *args 
and **kwargs can be now used multiple times in the call, there are 
opcodes for packing arguments: BUILD_LIST_UNPACK and 
BUILD_MAP_UNPACK_WITH_CALL.




More information about the Python-ideas mailing list