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>
2022-12-14 18:17:38 -08:00
..
cibuild all: use cibuild.On 2022-03-18 15:19:26 -07:00
clientmetric all: fix spelling mistakes 2022-09-29 13:36:13 -07:00
cloudenv all: use syncs.AtomicValue 2022-08-04 11:52:16 -07:00
cmpver util/cmpver: move into OSS from corp repo. 2021-04-23 20:55:45 -07:00
codegen all: convert more code to use net/netip directly 2022-07-25 21:53:49 -07:00
cstruct util/endian: delete package; use updated josharian/native instead 2022-12-12 20:12:45 -08:00
deephash types/ptr: move all the ptrTo funcs to one new package's ptr.To 2022-11-30 17:50:51 -08:00
dirwalk util/dirwalk, metrics, portlist: add new package for fast directory walking 2022-11-05 16:26:51 -07:00
dnsname all: fix spelling mistakes 2022-09-29 13:36:13 -07:00
goroutines ipn/ipnlocal: add c2n /debug/{goroutines,prefs,metrics} 2022-09-26 11:16:38 -07:00
groupmember util/groupmember: remove redundant code (#4298) 2022-03-26 21:45:06 -07:00
hashx util/hashx: move from sha256x (#5388) 2022-08-16 13:15:33 -07:00
jsonutil all: use any instead of interface{} 2022-03-17 11:35:09 -07:00
lineread util/lineread: add docs to Reader 2020-11-19 12:14:58 -08:00
mak all: fix spelling mistakes 2022-09-29 13:36:13 -07:00
multierr util/multierr: optimize New for nil cases (#6750) 2022-12-14 18:17:38 -08:00
must util/must: rename Do->Get, add Do 2022-08-06 09:30:10 -07:00
osshare all: remove old +build tags 2022-11-04 07:25:42 -07:00
pidowner all: remove old +build tags 2022-11-04 07:25:42 -07:00
precompress cmd/tsconnect: pre-compress main.wasm when building the NPM package 2022-10-14 15:08:06 -07:00
quarantine cmd/tailscale, util/quarantine: set quarantine flags on files from Taildrop 2022-11-17 15:06:02 -05:00
racebuild all: remove old +build tags 2022-11-04 07:25:42 -07:00
set util/set: add new set package for SetHandle type 2022-11-28 10:44:17 -08:00
singleflight util/singleflight: sync with upstream 2022-09-30 06:55:04 -07:00
strs util/strs: add new package for string utility funcs 2022-08-05 15:06:08 -07:00
systemd all: remove old +build tags 2022-11-04 07:25:42 -07:00
uniq util/uniq: add ModifySliceFunc (#5504) 2022-08-30 18:51:18 -04:00
winutil ipn/ipnauth, util/winutil: add temporary LookupPseudoUser workaround to address os/user.LookupId errors on Windows 2022-11-28 15:53:34 -06:00