[issue24221] Clean-up and optimization for heapq siftup() and siftdown()

2015-05-22 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 490720fc1525 by Raymond Hettinger in branch 'default':
Issue #24221:  Small optimizations for heapq.
https://hg.python.org/cpython/rev/490720fc1525

--
nosy: +python-dev

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24221
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24221] Clean-up and optimization for heapq siftup() and siftdown()

2015-05-22 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24221
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24221] Clean-up and optimization for heapq siftup() and siftdown()

2015-05-22 Thread Stefan Behnel

Stefan Behnel added the comment:

There are calls to PyObject_RichCompareBool() in the loops, which means that 
user code might get executed. What if that's evil code that modifies the heap 
list? Couldn't that lead to list resizing and thus invalidation of the list 
item pointer?

--
nosy: +scoder

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24221
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24221] Clean-up and optimization for heapq siftup() and siftdown()

2015-05-22 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

The list item pointer is updated just after calling PyObject_RichCompareBool(). 
The code LGTM.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24221
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24221] Clean-up and optimization for heapq siftup() and siftdown()

2015-05-22 Thread Stefan Behnel

Stefan Behnel added the comment:

Ah, sorry, yes. I somehow misread the arguments being passed *into* richcompare 
as subsequent array access. LGTM too. Sorry for the noise.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24221
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24221] Clean-up and optimization for heapq siftup() and siftdown()

2015-05-18 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Perhaps the code will look simpler if introduce the macro 
_PyList_SWAP_ITEMS(list, i, j).

--
nosy: +serhiy.storchaka

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24221
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24221] Clean-up and optimization for heapq siftup() and siftdown()

2015-05-17 Thread Raymond Hettinger

New submission from Raymond Hettinger:

The siftup() and siftdown() routines rearrange pointers in a list.  The 
generated code repeats the list object to ob_item lookup for each access.  This 
patch does that lookup only once per iteration.  It cleans up the code by 
replacing the PyList_GET_ITEM and PyList_SET_ITEM macros with normal array 
access (the usual way of presenting the algorithm).

This gives about a 5% speed-up using CLANG (timing heapify(data[:]) for n=1000 
goes from .3441 per iteration to .3299).   However on GCC-4.9, the same patch 
gives a 2% slow-down (disassembly shows that this patch triggers a register 
spill and load in the inner loop which is a bummer).

Since it speeds-up some builds and slows down others, I'm uncertain what to do 
with this one.  I like the way the code reads with array accesses but was 
aiming for a consistent win.   Am posting the patch here to collect thoughts on 
the subject and to not lose the work.

--
components: Extension Modules
files: heapitems5.diff
keywords: patch
messages: 243444
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Clean-up and optimization for heapq siftup() and siftdown()
type: performance
versions: Python 3.5
Added file: http://bugs.python.org/file39413/heapitems5.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24221
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24221] Clean-up and optimization for heapq siftup() and siftdown()

2015-05-17 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


Added file: http://bugs.python.org/file39414/time_heapify.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24221
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue24221] Clean-up and optimization for heapq siftup() and siftdown()

2015-05-17 Thread Raymond Hettinger

Changes by Raymond Hettinger raymond.hettin...@gmail.com:


--
priority: normal - low

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue24221
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com