-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancehelp wanted
Milestone
Description
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.
Init benchmark:
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)
Whole sortByRFC6724 function benchmark:
name old time/op new time/op delta
SortByRFC6724/0-8 479ns ± 0% 290ns ± 0% ~ (p=1.000 n=1+1)
SortByRFC6724/1-8 482ns ± 0% 291ns ± 0% ~ (p=1.000 n=1+1)
SortByRFC6724/2-8 489ns ± 0% 297ns ± 0% ~ (p=1.000 n=1+1)
SortByRFC6724/3-8 580ns ± 0% 367ns ± 0% ~ (p=1.000 n=1+1)
SortByRFC6724/4-8 934ns ± 0% 574ns ± 0% ~ (p=1.000 n=1+1)
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.Performancehelp wanted