art icon indicating copy to clipboard operation
art copied to clipboard

switch to using netaddr.IPPrefix instead of uint64

Open JulianKnodt opened this issue 2 years ago • 3 comments

By switching to []byte, it allows for arbitrary length addresses with a single API. Notably, it should allow for IPv6 and also naturally unifies with the type alias for IP: []byte.

All of the tests now are not really "unit", since I was pretty lazy and made them all use the highest level API, but that means they are more thorough than prior (but less compartmentalized).

Here's the new benchmark, I'll try cleaning it up to allocate less:

name                                 old time/op    new time/op    delta
MultiIPv4_stride8/InsertRemove-8       8.80µs ± 3%    9.35µs ± 6%   +6.19%  (p=0.001 n=10+9)
MultiIPv4_stride8/Search-8             27.9ns ± 4%    40.1ns ± 3%  +43.84%  (p=0.000 n=10+9)
MultiIPv4_stride16_8/InsertRemove-8    93.1µs ± 2%    98.8µs ± 5%   +6.17%  (p=0.000 n=9+10)
MultiIPv4_stride16_8/Search-8          21.2ns ± 1%    30.4ns ± 4%  +43.51%  (p=0.000 n=8+10)

name                                 old alloc/op   new alloc/op   delta
MultiIPv4_stride8/InsertRemove-8       19.4kB ± 0%    19.4kB ± 0%   -0.26%  (p=0.000 n=10+10)
MultiIPv4_stride8/Search-8              0.00B          0.00B          ~     (all equal)
MultiIPv4_stride16_8/InsertRemove-8    9.66kB ± 0%    9.64kB ± 0%   -0.17%  (p=0.001 n=9+8)
MultiIPv4_stride16_8/Search-8           0.00B          0.00B          ~     (all equal)

name                                 old allocs/op  new allocs/op  delta
MultiIPv4_stride8/InsertRemove-8         4.00 ± 0%      4.00 ± 0%     ~     (all equal)
MultiIPv4_stride8/Search-8               0.00           0.00          ~     (all equal)
MultiIPv4_stride16_8/InsertRemove-8      2.00 ± 0%      2.00 ± 0%     ~     (all equal)
MultiIPv4_stride16_8/Search-8            0.00           0.00          ~     (all equal)

Benchmarks after changing to IPPrefix:

name                                 old time/op    new time/op    delta
MultiIPv4_stride8/InsertRemove-8       6.58µs ± 7%    7.12µs ±11%   +8.19%  (p=0.006 n=10+9)
MultiIPv4_stride8/Search-8             23.0ns ± 4%    42.4ns ±12%  +84.30%  (p=0.000 n=7+9)
MultiIPv4_stride16_8/InsertRemove-8    70.5µs ±15%   107.0µs ±11%  +51.84%  (p=0.000 n=10+10)
MultiIPv4_stride16_8/Search-8          17.7ns ± 5%    32.9ns ±11%  +86.46%  (p=0.000 n=8+9)

name                                 old alloc/op   new alloc/op   delta
MultiIPv4_stride8/InsertRemove-8       19.4kB ± 0%    19.4kB ± 0%   -0.26%  (p=0.000 n=10+10)
MultiIPv4_stride8/Search-8              0.00B          0.00B          ~     (all equal)
MultiIPv4_stride16_8/InsertRemove-8    9.60kB ± 0%    9.70kB ± 0%   +1.11%  (p=0.000 n=10+9)
MultiIPv4_stride16_8/Search-8           0.00B          0.00B          ~     (all equal)

name                                 old allocs/op  new allocs/op  delta
MultiIPv4_stride8/InsertRemove-8         4.00 ± 0%      4.00 ± 0%     ~     (all equal)
MultiIPv4_stride8/Search-8               0.00           0.00          ~     (all equal)
MultiIPv4_stride16_8/InsertRemove-8      2.00 ± 0%      2.00 ± 0%     ~     (all equal)
MultiIPv4_stride16_8/Search-8            0.00           0.00          ~     (all equal)

JulianKnodt avatar Jul 11 '21 23:07 JulianKnodt

Can you send the benchmarks separately?

Also, net.IP isn't aliased to []byte. A type alias is a different thing. You meant an "underlying type": https://golang.org/ref/spec#Types

bradfitz avatar Jul 13 '21 05:07 bradfitz

the subtleness between "underlying type" and "type alias" is too much for me

JulianKnodt avatar Jul 13 '21 05:07 JulianKnodt

Not sure if the environment I'm running is just super noisy cause it's my personal computer, or if the byte slice version was better

JulianKnodt avatar Jul 13 '21 06:07 JulianKnodt