On the following code, f() uses CALL_FUNCTION_EX bytecode to call g(). The bytecode loads 'kw' variable which is a dictionary. But internally, the dictionary is converted to a temporary tuple, and later a new dictionary is created. Maybe the temporary tuple could be avoided?
def g(*args, **kw):
...
def f(*args, **kw):
g(*args, **kw)
In Python 3.6, before FASTCALL, CALL_FUNCTION_EX calls:
* do_call_core(): kw dict
* PyObject_Call(): kw dict
* function_call(): kw dict -> create a temporary tuple of keys and names: (key[0], value[0], ...)
* _PyEval_EvalCodeWithName(): if CO_VARKEYWORDS, rebuild a new dictionary for keyword arguments (**kw)
In Python master branch (future 3.8) with FASTCALL, CALL_FUNCTION_EX calls:
* do_call_core(): kw dict
* _PyFunction_FastCallDict(): kw dict -> a temporary tuple for keyword names ('kwnames') is created
* _PyEval_EvalCodeWithName(): if CO_VARKEYWORDS, rebuild a new dictionary for keyword arguments (**kw)
To be clear: FASTCALL didn't make this specific function call (Python => Python with **kw) worse nor better. |