[New-bugs-announce] [issue21148] avoid memset in small tuple creation

Julian Taylor report at bugs.python.org
Thu Apr 3 20:39:32 CEST 2014


New submission from Julian Taylor:

attached a prototype patch that avoids the memset of ob_item in PyTuple_New which is not necessary for the BUILD_TUPLE bytecode and PyTuple_Pack as these overwrite every entry in ob_item anyway.
This improves small tuple creation by about 5%.

It does this by adding a new internal function that does not use the memset loop and wrapping that in PyTuple_New that does it. _Pack and ceval call the internal function.
The patch still needs cleanup I don't know where the signature for ceval.c would best go. Does the internal function need to be hidden from the DSO?

microbenchmark, compiled with gcc-4.8.2 on ubuntu 14.04 amd64, default configure options:

import timeit
print(min(timeit.repeat("(a,)", setup="a = 1; b = 1", repeat=5, number=10**7)))
print(min(timeit.repeat("(a, b)", setup="a = 1; b = 1", repeat=5, number=10**7)))

before:
0.45767
0.52926

after:
0.42652
0.50122

larger tuples do not profit much as the loading is more expensive in comparison.

----------
components: Interpreter Core
files: avoid-memset.patch
keywords: patch
messages: 215461
nosy: jtaylor
priority: normal
severity: normal
status: open
title: avoid memset in small tuple creation
type: performance
versions: Python 3.5
Added file: http://bugs.python.org/file34715/avoid-memset.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21148>
_______________________________________


More information about the New-bugs-announce mailing list