[issue28839] _PyFunction_FastCallDict(): replace PyTuple_New() with PyMem_Malloc()
STINNER Victor
report at bugs.python.org
Thu Dec 1 07:44:29 EST 2016
STINNER Victor added the comment:
> Note: Using a simple printf() in the C code, I noticed that it is not uncommon that _PyFunction_FastCallDict() is called with an empty dictionary for keyword arguments.
Simplified Python example where _PyFunction_FastCallDict() is called with an empty dictionary:
---
def f2():
pass
def wrapper(func, *args, **kw):
# CALL_FUNCTION_EX: func(**{}) calls PyObject_Call() with kwargs={} which
# calls _PyFunction_FastCallDict()
func(*args, **kw)
def f():
# CALL_FUNCTION: calling wrapper calls fast_function() which calls
# _PyEval_EvalCodeWithName() which creates an empty dictionary for kw
wrapper(f2)
f()
---
But on this specific case, the speedup is *very* small: 3 nanoseconds :-)
./python -m perf timeit -s 'kw={}' -s 'def func(): pass' --duplicate=1000 'func(**kw)'
(...)
Median +- std dev: [ref] 108 ns +- 4 ns -> [patch] 105 ns +- 5 ns: 1.02x faster (-2%)
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28839>
_______________________________________
More information about the Python-bugs-list
mailing list