-
Notifications
You must be signed in to change notification settings - Fork 36
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
Any interest in switching from net.IP to netip.Addr to encode IP addresses in Flows? #35
Comments
@antoninbas I don't have much time to work on this library anymore and don't use it in any production code, but I'd be happy to take patches to switch to netip. It would be a breaking change, but one with a well-documented way forward, and something that needs to happen at some point regardless. Happy someone is still using this! 🙂 |
antoninbas
added a commit
to antoninbas/conntrack
that referenced
this issue
Oct 10, 2023
Using the net/netip package instead of the net package can help reduce the memory footprint of the library and help reduce the number of heap allocations. This is a breaking change for consumers for the libray as exported types are updated to use fields of type netip.Addr instead of net.IP. Fixes ti-mo#35 Signed-off-by: Antonin Bas <abas@vmware.com>
antoninbas
added a commit
to antoninbas/conntrack
that referenced
this issue
Oct 12, 2023
Using the net/netip package instead of the net package can help reduce the memory footprint of the library and help reduce the number of heap allocations. This is a breaking change for consumers for the libray as exported types are updated to use fields of type netip.Addr instead of net.IP. We also remove the depedency on go-cmp and use assert.Equal instead in tests. Fixes ti-mo#35 Signed-off-by: Antonin Bas <abas@vmware.com>
ti-mo
pushed a commit
to antoninbas/conntrack
that referenced
this issue
Oct 16, 2023
Using the net/netip package instead of the net package can help reduce the memory footprint of the library and help reduce the number of heap allocations. This is a breaking change for consumers of the library as exported types are updated to use fields of type netip.Addr instead of net.IP. We also remove the depedency on go-cmp and use assert.Equal instead in tests. Fixes ti-mo#35 Signed-off-by: Antonin Bas <abas@vmware.com>
ti-mo
pushed a commit
that referenced
this issue
Oct 16, 2023
Using the net/netip package instead of the net package can help reduce the memory footprint of the library and help reduce the number of heap allocations. This is a breaking change for consumers of the library as exported types are updated to use fields of type netip.Addr instead of net.IP. We also remove the depedency on go-cmp and use assert.Equal instead in tests. Fixes #35 Signed-off-by: Antonin Bas <abas@vmware.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
netip
package was introduced in Go 1.18. Compared to the existingnet.IP
type, thenetip.Addr
type takes less memory, is immutable, and is comparable so it supports == and can be used as a map key.The
Flow
type for this library contains 3 fields of typeTuple
, each with 2 IP addresses, that's 6 IP addresses in total. For IPv6 connections, memory usage (when considering IP addresses only, not other fields), could go down from40*6 = 240B
to24*6 = 144B
. And in practice, for IPv4 addresses, we would see the same benefit, due to a bug in the unmarshalling code:conntrack/tuple.go
Lines 117 to 128 in 7b6dc48
Calling
net.IPv4(...)
creates a 16B slice (+ 24B slice header): https://cs.opensource.google/go/go/+/refs/tags/go1.21.1:src/net/ip.go;l=50-53One thing to keep in mind is that it would be a non-backward compatible change, but:
This is something I am happy to contribute. It will enable programs consuming this library to reduce their memory footprint, as well as start using the netip package more easily.
The text was updated successfully, but these errors were encountered: