[issue36030] add internal API function to create tuple without items array initialization

Sergey Fedoseev report at bugs.python.org
Tue Feb 19 03:02:44 EST 2019


New submission from Sergey Fedoseev <fedoseev.sergey at gmail.com>:

PyTuple_New() fills items array with NULLs to make usage of Py_DECREF() safe even when array is not fully filled with real items.
There are multiple cases when this initialization step can be avoided to improve performance. For example it gives such speed-up for PyList_AsTuple():

Before:
$ python -m perf timeit -s "l = [None] * 10**6" "tuple(l)"
.....................
Mean +- std dev: 4.43 ms +- 0.01 ms

After:
$ python -m perf timeit -s "l = [None] * 10**6" "tuple(l)"
.....................
Mean +- std dev: 4.11 ms +- 0.03 ms

----------
messages: 335897
nosy: sir-sigurd
priority: normal
severity: normal
status: open
title: add internal API function to create tuple without items array initialization
type: performance
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36030>
_______________________________________


More information about the Python-bugs-list mailing list