New submission from STINNER Victor <vstin...@redhat.com>:
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. ---------- components: Interpreter Core messages: 321400 nosy: inada.naoki, serhiy.storchaka, vstinner priority: normal severity: normal status: open title: Python function call optimization: avoid temporary tuple to pass **kwargs type: performance versions: Python 3.8 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34090> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com