Open ankenyr opened 1 year ago
Hi, just checking in on this. If this sounds good I am happy to create a PR.
Anyone interested in doing some benchmarks for these two approaches?
I was worried about that the summarize_address_range
to be the most expensive operation and eats up all remaining speed improvement it brings. IMO hiding the splitting loop part into this function call that uses loops internally might be detrimental to the readability to those who are not so familiar with IP, unless there are more significant benefits.
Happy to do any work, I see @iritkatriel added the label of stdlib to this. @iritkatriel from the link to the previous discussion Guido mentions that there should be a discussion on the approach. https://discuss.python.org/t/ipaddress-py-exclude-address-speed-up/19445/7
Can you let me know if my outline in the first message is enough and if I can go ahead with a PR? If not please advise on the next steps.
@StephDC I have implemented this in my own library and have found improvements. Happy to do some benchmarks though.
It is great that you have implemented it and found improvements. However, can you show us some real numbers so we can all agree that there are some improvements that worth the merge?
It would be helpful to include the following information:
Execution time for the same function with (columns)
for at least the following examples: (rows)
And don't forget to check that both function return the same result.
Feature or enhancement
Increase the speed of exclude_address by treating IPs as integer ranges making exclude_address O(1).
Pitch
Currently exclude_address will take a subnet and split it by calling subnets()
each time it is split, it checks which one contains the subnet being excluded and splits again. This ends up being a lot of work.
Instead I propose we can use the fact that IPs are represented as integers behind the scene
For a given subnet, it can be thought of as an integer range between its network and broadcast address
Given these can be treated as an integer range, excluding is just removing the range integers you wish to exclude
Previous discussion
https://discuss.python.org/t/ipaddress-py-exclude-address-speed-up/19445