New submission from STINNER Victor:

Attached patch changes index(), insert() and rotate() functions of the 
collections.deque type to use FASTCALL calling convention. I chose to only 
modify these functions since they use METH_VARARGS which requires to create a 
temporary tuple, whereas other functions use METH_NOARGS or METH_O which is 
already fast ;-)

I know that Raymond, maintainer of the collections module, is not a big fan of 
Argument Clinic ;-) So I wrote the minimum change and chose to not use Argument 
Clinic yet. By the way, the index() method has the signature "D.index(value, 
[start, [stop]])" which is not supported by Argument Clinic yet: see issue 
#29299. For these reasons, I propose to wait to convert collections.deque to 
Argument Clinic, it can be done later.
 
Ok, now the cool part: it makes these methods faster ;-)

* d.rotate(): 1.10x faster
* d.rotate(1): 1.24x faster
* d.insert(): 1.18x faster
* d.index(): 1.24x faster

$ ./python -m perf timeit -s 'import collections; d=collections.deque()' 
'd.rotate()' --compare-to=../default-ref/python 

Median +- std dev: [ref] 70.5 ns +- 0.9 ns -> [patch] 64.2 ns +- 0.3 ns: 1.10x 
faster (-9%)

$ ./python -m perf timeit -s 'import collections; d=collections.deque()' 
'd.rotate(1)' --compare-to=../default-ref/python

Median +- std dev: [ref] 107 ns +- 1 ns -> [patch] 86.2 ns +- 1.1 ns: 1.24x 
faster (-20%)

$ ./python -m perf timeit -s 'import collections' 'd=collections.deque(); 
d.insert(0, None); d.insert(1, None); d.insert(2, None); d.insert(3, None); 
d.insert(4, None)' --compare-to=../default-ref/python -p3

Median +- std dev: [ref] 699 ns +- 6 ns -> [patch] 591 ns +- 5 ns: 1.18x faster 
(-15%)

$ ./python -m perf timeit -s 'import collections; d=collections.deque((None,))' 
'd.index(None)' --compare-to=../default-ref/python 

Median +- std dev: [ref] 115 ns +- 1 ns -> [patch] 92.5 ns +- 0.8 ns: 1.24x 
faster (-19%)

----------
files: deque.patch
keywords: patch
messages: 287044
nosy: haypo, rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Use FASTCALL for collections.deque methods: index, insert, rotate
type: performance
versions: Python 3.7
Added file: http://bugs.python.org/file46523/deque.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29452>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to