As net package has one of the biggest init time in standard library, I have tried to improve performance by doing two things in net/addrselect.go:
Precompute slice with RFC rules. Currently the rules are computed and sorted in init() function. We could save the time and allocations by using prepopulated values in sorted manner. The rules haven't changed since 2015. To be extra safe we could move order validation as test case. It should slightly speed up startup of each binary with "net" package and go dns resolver. It also saves 38 allocations, ~50% of allocations in init phase of net module.
Replace internal net.IP usage with netip.Addr in sortByRFC6724 function. It results in ~40% performance improvement on samples from tests.
The only risk is the difference between net.IP and netip.Addr behaviour.
name old time/op new time/op delta
Init-8 2.14µs ± 0% 0.12µs ± 0% ~ (p=1.000 n=1+1)
name old alloc/op new alloc/op delta
Init-8 1.05kB ± 0% 0.38kB ± 0% ~ (p=1.000 n=1+1)
name old allocs/op new allocs/op delta
Init-8 39.0 ± 0% 1.0 ± 0% ~ (p=1.000 n=1+1)