You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailscale/util
Joe Tsai 350aab05e5
util/multierr: optimize New for nil cases (#6750)
Consider the following pattern:

	err1 := foo()
	err2 := bar()
	err3 := baz()
	return multierr.New(err1, err2, err3)

If err1, err2, and err3 are all nil, then multierr.New should not allocate.
Thus, modify the logic of New to count the number of distinct error values
and allocate the exactly needed slice. This also speeds up non-empty error
situation since repeatedly growing with append is slow.

Performance:

	name         old time/op    new time/op    delta
	Empty-24       41.8ns ± 2%     6.4ns ± 1%   -84.73%  (p=0.000 n=10+10)
	NonEmpty-24     120ns ± 3%      69ns ± 1%   -42.01%  (p=0.000 n=9+10)

	name         old alloc/op   new alloc/op   delta
	Empty-24        64.0B ± 0%      0.0B       -100.00%  (p=0.000 n=10+10)
	NonEmpty-24      168B ± 0%       88B ± 0%   -47.62%  (p=0.000 n=10+10)

	name         old allocs/op  new allocs/op  delta
	Empty-24         1.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
	NonEmpty-24      3.00 ± 0%      2.00 ± 0%   -33.33%  (p=0.000 n=10+10)

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
2 years ago
..
cibuild all: use cibuild.On 3 years ago
clientmetric all: fix spelling mistakes 2 years ago
cloudenv all: use syncs.AtomicValue 2 years ago
cmpver util/cmpver: move into OSS from corp repo. 4 years ago
codegen all: convert more code to use net/netip directly 2 years ago
cstruct util/endian: delete package; use updated josharian/native instead 2 years ago
deephash types/ptr: move all the ptrTo funcs to one new package's ptr.To 2 years ago
dirwalk util/dirwalk, metrics, portlist: add new package for fast directory walking 2 years ago
dnsname all: fix spelling mistakes 2 years ago
goroutines ipn/ipnlocal: add c2n /debug/{goroutines,prefs,metrics} 2 years ago
groupmember util/groupmember: remove redundant code (#4298) 3 years ago
hashx util/hashx: move from sha256x (#5388) 2 years ago
jsonutil all: use any instead of interface{} 3 years ago
lineread util/lineread: add docs to Reader 4 years ago
mak all: fix spelling mistakes 2 years ago
multierr util/multierr: optimize New for nil cases (#6750) 2 years ago
must util/must: rename Do->Get, add Do 2 years ago
osshare all: remove old +build tags 2 years ago
pidowner all: remove old +build tags 2 years ago
precompress cmd/tsconnect: pre-compress main.wasm when building the NPM package 2 years ago
quarantine cmd/tailscale, util/quarantine: set quarantine flags on files from Taildrop 2 years ago
racebuild all: remove old +build tags 2 years ago
set util/set: add new set package for SetHandle type 2 years ago
singleflight util/singleflight: sync with upstream 2 years ago
strs util/strs: add new package for string utility funcs 2 years ago
systemd all: remove old +build tags 2 years ago
uniq util/uniq: add ModifySliceFunc (#5504) 2 years ago
winutil ipn/ipnauth, util/winutil: add temporary LookupPseudoUser workaround to address os/user.LookupId errors on Windows 2 years ago