[issue10227] Improve performance of MemoryView slicing

Stefan Behnel report at bugs.python.org
Wed Feb 2 19:48:35 CET 2011


Stefan Behnel <scoder at users.sourceforge.net> added the comment:

> Any benchmark numbers for the slice cache?

I ran the list tests in pybench and got this:

Test               minimum run-time        average  run-time
                    this    other   diff    this    other   diff
--------------------------------------------------------------------
    ListSlicing:    66ms    67ms   -2.2%    67ms    68ms   -2.7%
     SmallLists:    61ms    64ms   -4.5%    61ms    65ms   -5.6%
--------------------------------------------------------------------
Totals:           127ms   131ms   -3.3%   128ms   133ms   -4.1%

Repeating this gave me anything between 1.5% and 3.5% in total, with >2% for the small lists benchmark (which is the expected best case as slicing large lists obviously dominates the slice object creation).

IMHO, even 2% would be pretty good for such a small change.


> Also, is the call to PyObject_INIT necessary?

In any case, the ref-count needs to be re-initialised to 1. A call to _Py_NewReference() would be enough, though, following the example in listobject.c. So you can replace

         PyObject_INIT(obj, &PySlice_Type);

by

         _Py_NewReference((PyObject *)obj);

in the patch. New patch attached.

----------
Added file: http://bugs.python.org/file20650/slice-object-cache.patch

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


More information about the Python-bugs-list mailing list