You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Python, __getitem___ has been preferred over __getslice__ for ages and __getslice__ is gone for good in Python 3. However, Cython still generates slicing code instead of item getting code for performance reasons. It hard codes the slice sizes and calls PySequence_GetSlice() with Py_ssize_t arguments. This leads to a difference to Python when creating the slice object.
In Python, obj[:] calls the object's __getitem__ method with slice(None,None,None) as argument. In Cython, the slice is created as slice(0,PY_SSIZE_T_MAX,None).
At least in Python 3, where PySequence_GetSlice() always creates a slice object, this is worth fixing (and optimising by using a constant slice object for constant cases). In Python 2, the slice object is only created when the class defines __getitem__ and not __getslice__, which makes it trickier to fix.
Note that the same applies to SetItem and DelItem.
Also note that it is not enough to translate any Py_SSIZE_T_MAX into None, as the user may well have deliberately used this value.
Compared to Python 2.7, the ListSlicing test in pybench runs slower:
Test minimum run-time average run-time
this other diff this other diff
------------------------------------------------------------
ListSlicing: 696ms 647ms +7.6% 788ms 673ms +17.2%
In Python,
__getitem___
has been preferred over__getslice__
for ages and__getslice__
is gone for good in Python 3. However, Cython still generates slicing code instead of item getting code for performance reasons. It hard codes the slice sizes and callsPySequence_GetSlice()
withPy_ssize_t
arguments. This leads to a difference to Python when creating the slice object.In Python,
obj[:]
calls the object's__getitem__
method withslice(None,None,None)
as argument. In Cython, the slice is created asslice(0,PY_SSIZE_T_MAX,None)
.At least in Python 3, where
PySequence_GetSlice()
always creates a slice object, this is worth fixing (and optimising by using a constant slice object for constant cases). In Python 2, the slice object is only created when the class defines__getitem__
and not__getslice__
, which makes it trickier to fix.Note that the same applies to
SetItem
andDelItem
.Also note that it is not enough to translate any
Py_SSIZE_T_MAX
intoNone
, as the user may well have deliberately used this value.First reported for Debian here:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=604963
Migrated from http://trac.cython.org/ticket/636
The text was updated successfully, but these errors were encountered: