[issue23553] Reduce the number of comparison for range checking.

2015-03-01 Thread Arfrever Frehtes Taifersar Arahesis
Changes by Arfrever Frehtes Taifersar Arahesis : -- nosy: +Arfrever ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscri

[issue23553] Reduce the number of comparison for range checking.

2015-03-01 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: My point is that if the benefit is too small (say < 5% in microbenchmarks), it is not worth code churning. Actually my bar for microbenchmarks is higher, about 20%. -- ___ Python tracker

[issue23553] Reduce the number of comparison for range checking.

2015-03-01 Thread Roundup Robot
Roundup Robot added the comment: New changeset 1e89094998b2 by Raymond Hettinger in branch 'default': Issue #23553: Use an unsigned cast to tighten-up the bounds checking logic. https://hg.python.org/cpython/rev/1e89094998b2 -- nosy: +python-dev ___

[issue23553] Reduce the number of comparison for range checking.

2015-03-01 Thread Raymond Hettinger
Raymond Hettinger added the comment: I think the source in listobject.c would be benefit from a well-named macro for this. That would provide the most clarity. For deques, I'll just put in the simple patch because it only applies to a place that is already doing unsigned arithmetic/comparis

[issue23553] Reduce the number of comparison for range checking.

2015-03-01 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Parenthesis around Py_SIZE() are redundant. Are there any benchmarking results that show a speed up? Such microoptimization makes sense in tight loops, but optimized source code looks more cumbersome and errorprone. -- nosy: +pitrou ___

[issue23553] Reduce the number of comparison for range checking.

2015-02-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: Also attaching a bounds checking patch for deques. -- Added file: http://bugs.python.org/file38283/bounds_check_deque.diff ___ Python tracker ___

[issue23553] Reduce the number of comparison for range checking.

2015-02-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: Attaching a diff for the bounds checking Objects/listobject.c. It looks like elsewhere in that file, (size_t) casts are done for various reasons. -- Added file: http://bugs.python.org/file38282/bounds_check_list.diff _

[issue23553] Reduce the number of comparison for range checking.

2015-02-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It looks correct to me, but I would change type and introduce few new variables to get rid of casts. -- ___ Python tracker ___ __

[issue23553] Reduce the number of comparison for range checking.

2015-02-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: > But it wouldn't work for say off_t. I'm only proposing a bounds checking macro for the Py_ssize_t case which is what all of our IndexError tests look for. Also, please look at the attached deque fix. -- ___ Py

[issue23553] Reduce the number of comparison for range checking.

2015-02-28 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- keywords: +patch Added file: http://bugs.python.org/file38281/size_t.diff ___ Python tracker ___ ___

[issue23553] Reduce the number of comparison for range checking.

2015-02-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > Wouldn't size_t always work for Py_ssize_t? Yes. But it wouldn't work for say off_t. The consistent way is always use size_t instead of Py_ssize_t. But this boat has sailed. -- ___ Python tracker

[issue23553] Reduce the number of comparison for range checking.

2015-02-28 Thread Raymond Hettinger
Raymond Hettinger added the comment: > The type of i and Py_SIZE(a) is Py_ssize_t, so when casted to > unsigned int, highest bits are lost. The correct casting type is size_t. Yes, I had just seen that a early today and deciding whether to substitute size_t for the unsigned cast or whether to

[issue23553] Reduce the number of comparison for range checking.

2015-02-28 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Yes, this is a technique commonly used in STL implementations. This is why sizes and indices in STL are unsigned. But in CPython implementation sizes are signed (Py_ssize_t). The problem with using this optimization (rather low-level than high-level) is that

[issue23553] Reduce the number of comparison for range checking.

2015-02-28 Thread Raymond Hettinger
New submission from Raymond Hettinger: Python's core is full of bound checks like this one in Objects/listobject.c: static PyObject * list_item(PyListObject *a, Py_ssize_t i) { if (i < 0 || i >= Py_SIZE(a)) { ... Abner Fog's high-level language optimization guide, http://www.agner.org