Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted ipaddress performance improvements #65686

Closed
pitrou opened this issue May 12, 2014 · 6 comments
Closed

Assorted ipaddress performance improvements #65686

pitrou opened this issue May 12, 2014 · 6 comments
Labels
performance Performance or resource usage stdlib Python modules in the Lib dir

Comments

@pitrou
Copy link
Member

pitrou commented May 12, 2014

BPO 21487
Nosy @ncoghlan, @pitrou, @serhiy-storchaka
Files
  • ipaddr_perf.patch
  • ipaddr_perf2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2014-05-15.19:05:59.847>
    created_at = <Date 2014-05-12.20:04:23.234>
    labels = ['library', 'performance']
    title = 'Assorted ipaddress performance improvements'
    updated_at = <Date 2014-05-15.19:05:59.847>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2014-05-15.19:05:59.847>
    actor = 'pitrou'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-05-15.19:05:59.847>
    closer = 'pitrou'
    components = ['Library (Lib)']
    creation = <Date 2014-05-12.20:04:23.234>
    creator = 'pitrou'
    dependencies = []
    files = ['35234', '35251']
    hgrepos = []
    issue_num = 21487
    keywords = ['patch']
    message_count = 6.0
    messages = ['218357', '218515', '218525', '218568', '218607', '218622']
    nosy_count = 5.0
    nosy_names = ['ncoghlan', 'pitrou', 'pmoody', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue21487'
    versions = ['Python 3.5']

    @pitrou
    Copy link
    Member Author

    pitrou commented May 12, 2014

    Now that issue bpo-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.

    @pitrou pitrou added stdlib Python modules in the Lib dir performance Performance or resource usage labels May 12, 2014
    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented May 14, 2014

    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()

    @pitrou
    Copy link
    Member Author

    pitrou commented May 14, 2014

    Good point, this is a much faster implementation. Updated patch (and fixed the implementation to not return more than bits).

    @serhiy-storchaka
    Copy link
    Member

    serhiy-storchaka commented May 14, 2014

    Looks as second alternative is few percents faster then first one.

    @pitrou
    Copy link
    Member Author

    pitrou commented May 15, 2014

    I find logical operations on negative numbers confusing in Python, so I'd rather stick with the first implementation.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented May 15, 2014

    New changeset 2711677cf874 by Antoine Pitrou in branch 'default':
    Issue bpo-21487: Optimize ipaddress.summarize_address_range() and ipaddress.{IPv4Network,IPv6Network}.subnets().
    http://hg.python.org/cpython/rev/2711677cf874

    @pitrou pitrou closed this as completed May 15, 2014
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    performance Performance or resource usage stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants