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
David Anderson 0909e90890 util/lru: replace container/list with a custom ring implementation
pre-generics container/list is quite unpleasant to use, and the pointer
manipulation operations for an LRU are simple enough to implement directly
now that we have generic types.

With this change, the LRU uses a ring (aka circularly linked list) rather
than a simple doubly-linked list as its internals, because the ring makes
list manipulation edge cases more regular: the only remaining edge case is
the transition between 0 and 1 elements, rather than also having to deal
specially with manipulating the first and last members of the list.

While the primary purpose was improved readability of the code, as it
turns out removing the indirection through an interface box also speeds
up the LRU:

       │ before.txt  │              after.txt              │
       │   sec/op    │   sec/op     vs base                │
LRU-32   67.05n ± 2%   59.73n ± 2%  -10.90% (p=0.000 n=20)

       │ before.txt │             after.txt              │
       │    B/op    │    B/op     vs base                │
LRU-32   21.00 ± 0%   10.00 ± 0%  -52.38% (p=0.000 n=20)

       │ before.txt │           after.txt            │
       │ allocs/op  │ allocs/op   vs base            │
LRU-32   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=20) ¹

Updates #cleanup

Signed-off-by: David Anderson <danderson@tailscale.com>
10 months ago
..
cibuild all: update copyright and license headers 1 year ago
clientmetric util/clientmetric: allow client metric values to be provided by a function 1 year ago
cloudenv all: update copyright and license headers 1 year ago
cmpver util/cmpver: add a few tests covering different OS versions 10 months ago
cmpx all: update exp/slices and fix call sites 11 months ago
codegen util/codegen: support embedded fields 1 year ago
cstruct all: update copyright and license headers 1 year ago
deephash util/deephash: add IncludeFields, ExcludeFields HasherForType Options 10 months ago
dirwalk all: use tstest.Replace more 1 year ago
dnsname cmd/tailscale: extend hostname validation (#7678) 1 year ago
goroutines util/goroutines: let ScrubbedGoroutineDump get only current stack 1 year ago
groupmember all: update copyright and license headers 1 year ago
hashx all: update copyright and license headers 1 year ago
httpm all: update copyright and license headers 1 year ago
jsonutil all: update copyright and license headers 1 year ago
limiter util/limiter: add a keyed token bucket rate limiter 10 months ago
lineread all: update copyright and license headers 1 year ago
linuxfw client/web, clientupdate, util/linuxfw, wgengine/magicsock: Use %v verb for errors 10 months ago
lru util/lru: replace container/list with a custom ring implementation 10 months ago
mak various: add golangci-lint, fix issues (#7905) 1 year ago
multierr all: use Go 1.21 slices, maps instead of x/exp/{slices,maps} 11 months ago
must all: update copyright and license headers 1 year ago
osdiag util/osdiag: add query for Windows page file configuration and status 10 months ago
osshare all: update copyright and license headers 1 year ago
pidowner all: update copyright and license headers 1 year ago
precompress all: update copyright and license headers 1 year ago
quarantine all: update copyright and license headers 1 year ago
racebuild all: update copyright and license headers 1 year ago
rands util/rands: add package with HexString func 10 months ago
ringbuffer util/ringbuffer: move generic ringbuffer from corp repo 1 year ago
set cmd/k8s-operator: add metrics to track usage 10 months ago
singleflight all: update copyright and license headers 1 year ago
slicesx all: use Go 1.21 slices, maps instead of x/exp/{slices,maps} 11 months ago
sysresources util/sysresources, magicsock: scale DERP buffer based on system memory 1 year ago
systemd all: update copyright and license headers 1 year ago
testenv util/testenv: add new package to hold InTest 11 months ago
truncate util: add truncate package (#7490) 1 year ago
uniq all: update copyright and license headers 1 year ago
vizerror util/vizerror: add As function to get wrapped Error 1 year ago
winutil util/winutil: add RegisterForRestart, allowing programs to indicate their preferences to the Windows restart manager 11 months ago