all: use bart.Lite instead of bart.Table where appropriate

When we don't care about the payload value and are just checking whether
a set contains an IP/prefix, we can use `bart.Lite` for the same lookup
times but a lower memory footprint.

Fixes #19075

Change-Id: Ia709e8b718666cc61ea56eac1066467ae0b6e86c
Signed-off-by: Alex Chan <alexc@tailscale.com>
This commit is contained in:
Alex Chan
2026-03-23 15:22:17 +00:00
committed by Alex Chan
parent 44ec71cf94
commit 1d0fde6fc2
4 changed files with 16 additions and 26 deletions
+3 -10
View File
@@ -20,13 +20,6 @@ func FalseContainsIPFunc() func(ip netip.Addr) bool {
func emptySet(ip netip.Addr) bool { return false }
func bartLookup(t *bart.Table[struct{}]) func(netip.Addr) bool {
return func(ip netip.Addr) bool {
_, ok := t.Lookup(ip)
return ok
}
}
func prefixContainsLoop(addrs []netip.Prefix) func(netip.Addr) bool {
return func(ip netip.Addr) bool {
for _, p := range addrs {
@@ -81,11 +74,11 @@ func NewContainsIPFunc(addrs views.Slice[netip.Prefix]) func(ip netip.Addr) bool
}
pathForTest("bart")
// Built a bart table.
t := &bart.Table[struct{}]{}
t := &bart.Lite{}
for _, p := range addrs.All() {
t.Insert(p, struct{}{})
t.Insert(p)
}
return bartLookup(t)
return t.Contains
}
// Fast paths for 1 and 2 IPs:
if addrs.Len() == 1 {