mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-24 17:48:57 +00:00
wgengine/filter: preallocate some hot slices in MatchesFromFilterRules (#4672)
Profiling identified this as a fairly hot path for growing a slice. Given this is only used in control & when a new packet filter is received, this shouldnt be hot in the client.
This commit is contained in:
@@ -28,7 +28,14 @@ func MatchesFromFilterRules(pf []tailcfg.FilterRule) ([]Match, error) {
|
||||
var erracc error
|
||||
|
||||
for _, r := range pf {
|
||||
m := Match{}
|
||||
// Profiling determined that this function was spending a lot
|
||||
// of time in runtime.growslice. As such, we attempt to
|
||||
// pre-allocate some slices. Multipliers were chosen arbitrarily.
|
||||
m := Match{
|
||||
Srcs: make([]netaddr.IPPrefix, 0, len(r.SrcIPs)),
|
||||
Dsts: make([]NetPortRange, 0, 2*len(r.DstPorts)),
|
||||
Caps: make([]CapMatch, 0, 3*len(r.CapGrant)),
|
||||
}
|
||||
|
||||
if len(r.IPProto) == 0 {
|
||||
m.IPProto = append([]ipproto.Proto(nil), defaultProtos...)
|
||||
|
||||
Reference in New Issue
Block a user