Avoiding a lot of duplicate work by pre-parsing IP networks in a lazy_static!.
Treating IPv4 and IPv6 addresses seperately. A v4 address can never be part of a v6 subnet.
Some rough benchmarks puts this change at a >100x preformance improvement for is_bogon for ipv4 addresses.
I expiremented with using a radix tree. I found it preformed ~45% faster on random ipv6 addresses but ~33% worse on random ipv4 addresses. I don't think it's worth the additional complexity to use a trie, yet.
While making this change I thought it would also be valuable to add:
pub fn is_bogon_addr(ip_address: IpAddr) -> bool;
This allows users to avoid some memory allocations in some use cases. We might also find some uses within this library later.
This PR improves the preformance of
is_bogon
bylazy_static!
.Some rough benchmarks puts this change at a >100x preformance improvement for
is_bogon
for ipv4 addresses.I expiremented with using a radix tree. I found it preformed ~45% faster on random ipv6 addresses but ~33% worse on random ipv4 addresses. I don't think it's worth the additional complexity to use a trie, yet.
While making this change I thought it would also be valuable to add:
This allows users to avoid some memory allocations in some use cases. We might also find some uses within this library later.