classification
Title: Assorted ipaddress performance improvements
Type: performance Stage: resolved
Components: Library (Lib) Versions: Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ncoghlan, pitrou, pmoody, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2014-05-12 20:04 by pitrou, last changed 2014-05-15 19:05 by pitrou. This issue is now closed.

Files
File name Uploaded Description Edit
ipaddr_perf.patch pitrou, 2014-05-12 20:04 review
ipaddr_perf2.patch pitrou, 2014-05-14 13:04 review
Messages (6)
msg218357 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-05-12 20:04
Now that issue #16531 has been committed, it becomes possible to make some operations faster. Attached patch makes summarize_address_range() ~2x faster and Network.subnets() ~4x faster.
msg218515 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-05-14 10:17
Alternative implementations of _count_righthand_zero_bits():

def _count_righthand_zero_bits(number, bits):
    if not number:
        return bits
    return (~number & (number-1)).bit_length()

or

def _count_righthand_zero_bits(number, bits):
    if not number:
        return bits
    return (~(number | -number)).bit_length()
msg218525 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-05-14 13:04
Good point, this is a much faster implementation. Updated patch (and fixed the implementation to not return more than `bits`).
msg218568 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-05-14 19:38
Looks as second alternative is few percents faster then first one.
msg218607 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-05-15 12:35
I find logical operations on negative numbers confusing in Python, so I'd rather stick with the first implementation.
msg218622 - (view) Author: Roundup Robot (python-dev) Date: 2014-05-15 18:21
New changeset 2711677cf874 by Antoine Pitrou in branch 'default':
Issue #21487: Optimize ipaddress.summarize_address_range() and ipaddress.{IPv4Network,IPv6Network}.subnets().
http://hg.python.org/cpython/rev/2711677cf874
History
Date User Action Args
2014-05-15 19:05:59pitrousetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2014-05-15 18:21:57python-devsetnosy: + python-dev
messages: + msg218622
2014-05-15 12:35:56pitrousetmessages: + msg218607
2014-05-14 19:38:11serhiy.storchakasetmessages: + msg218568
2014-05-14 13:04:09pitrousetfiles: + ipaddr_perf2.patch

messages: + msg218525
2014-05-14 10:17:17serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg218515
2014-05-12 20:04:23pitroucreate