netaddr icon indicating copy to clipboard operation
netaddr copied to clipboard

proposal: add a trie type for efficient route lookups using netaddr.IP{,Prefix}

Open mdlayher opened this issue 4 years ago • 9 comments

I'd like to introduce netaddr in an application at work that uses a big trie full of routes using net.IP and net.IPNet. I suspect there could be some serious performance/memory improvements by using netaddr instead and I think it could be a fun educational project for me too.

Would there be interest in having this as part of the upstream library? I can always start out with my own repo too.

/cc @bradfitz @danderson @josharian

mdlayher avatar Feb 19 '21 21:02 mdlayher

Also with generics on the horizon it's possible that building such a thing might be a lot more ergonomic in a year or two. I personally wouldn't mind yolo changing the API to swap out empty interfaces when possible, but I guess it'd also depend on what the compatibility plans are for netaddr.

mdlayher avatar Feb 19 '21 21:02 mdlayher

Brad started a SMART implementation. I've been meaning for ages to finish it up. I'd love it if you did. :) I'm pretty sure wireguard-go would use one too. I think it should probably go in a separate package, but I'm +1 on inet.af/smart. I agree that generics would help with IPv4 vs IPv6, but initially I'd say just make two copies and we can reduce to one with generics as appropriate. We could even do it without API changes, just swap in a generic backend. The SMART implementation might also be a reason to extract out uint128 support into a separate package, since you won't need zones in your routing table. (Or give up on space efficiency and write just one that uses full IPs at every node!)

josharian avatar Feb 19 '21 22:02 josharian

Brad started a SMART implementation. I've been meaning for ages to finish it up. I'd love it if you did. :)

Have a link? I don't think I've seen it.

mdlayher avatar Feb 19 '21 22:02 mdlayher

Weird, I can't find it. But I'm certain it existed. @bradfitz?

josharian avatar Feb 20 '21 04:02 josharian

You had the name slightly off: https://github.com/bradfitz/art

That's the data type used by *BSD's network stack iirc, and is very efficient at a bunch of things, much moreso than a basic trie.

danderson avatar Feb 22 '21 18:02 danderson

Nice, thanks for the link. I will investigate that and see if I can help out.

mdlayher avatar Feb 22 '21 18:02 mdlayher

I no longer have a need for this and we've been integrated into stdlib, so I'm going to close this out.

mdlayher avatar Feb 08 '22 15:02 mdlayher

Fwiw, I still want this... Somewhere.

bradfitz avatar Feb 08 '22 15:02 bradfitz

@bradfitz ack, will reopen for tracking!

mdlayher avatar Feb 08 '22 15:02 mdlayher