[New-bugs-announce] [issue23507] Tuple creation is two slow

Serhiy Storchaka report at bugs.python.org
Tue Feb 24 09:08:32 CET 2015


New submission from Serhiy Storchaka:

Currently tuples creating uses free lists. But this optimization is not enough. When reuse cached tuple for arguments of repeatedly called functions, the performance of some builtins can be significantly increased.

$ ./python -m timeit -s "f = lambda x: x" -s "s = list(range(1000))" -- "list(filter(f, s))"
Unpatched: 1000 loops, best of 3: 773 usec per loop
Patched:   1000 loops, best of 3: 558 usec per loop

$ ./python -m timeit -s "f = lambda x: x" -s "s = list(range(1000))" -- "list(map(f, s))"
Unpatched: 1000 loops, best of 3: 689 usec per loop
Patched:   1000 loops, best of 3: 556 usec per loop

$ ./python -m timeit -s "f = lambda x: x" -s "s = list(range(1000))" -- "sorted(s, key=f)"
Unpatched: 1000 loops, best of 3: 758 usec per loop
Patched:   1000 loops, best of 3: 550 usec per loop

The same effect can be achieved for itertools functions.

I don't propose to commit this complicated patch, but these results can be used as a guide to the optimization of tuple creating. It is surprising to me that this patch has any effect at all.

----------
components: Interpreter Core
files: reuse_argtuples.patch
keywords: patch
messages: 236480
nosy: serhiy.storchaka
priority: normal
severity: normal
status: open
title: Tuple creation is two slow
type: performance
versions: Python 3.5
Added file: http://bugs.python.org/file38223/reuse_argtuples.patch

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


More information about the New-bugs-announce mailing list