a5fb8e0731
util/deephash: introduce deliberate instability ( #2477 )
...
Seed the hash upon first use with the current time.
This ensures that the stability of the hash is bounded within
the lifetime of one program execution.
Hopefully, this prevents future bugs where someone assumes that
this hash is stable.
Signed-off-by: Joe Tsai <joetsai@digital-static.net >
2021-07-21 09:23:04 -07:00
9a0c8bdd20
util/deephash: make hash type opaque
...
The fact that Hash returns a [sha256.Size]byte leaks details about
the underlying hash implementation. This could very well be any other
hashing algorithm with a possible different block size.
Abstract this implementation detail away by declaring an opaque type
that is comparable. While we are changing the signature of UpdateHash,
rename it to just Update to reduce stutter (e.g., deephash.Update).
Signed-off-by: Joe Tsai <joetsai@digital-static.net >
2021-07-20 11:03:25 -07:00
ddb8726c98
util/deephash: don't reflect.Copy if element type is a defined uint8
...
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
2021-07-07 11:58:04 -07:00
df176c82f5
util/deephash: skip alloc test under race detector
...
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
2021-07-07 11:40:28 -07:00
6dc38ff25c
util/deephash: optimize hashing of byte arrays, reduce allocs in Hash
...
name old time/op new time/op delta
Hash-6 173µs ± 4% 101µs ± 3% -41.69% (p=0.000 n=10+9)
HashMapAcyclic-6 101µs ± 5% 105µs ± 3% +3.52% (p=0.001 n=9+10)
TailcfgNode-6 29.4µs ± 2% 16.4µs ± 3% -44.25% (p=0.000 n=8+10)
name old alloc/op new alloc/op delta
Hash-6 3.60kB ± 0% 1.13kB ± 0% -68.70% (p=0.000 n=10+10)
HashMapAcyclic-6 2.53kB ± 0% 2.53kB ± 0% ~ (p=0.137 n=10+8)
TailcfgNode-6 528B ± 0% 0B -100.00% (p=0.000 n=10+10)
name old allocs/op new allocs/op delta
Hash-6 84.0 ± 0% 40.0 ± 0% -52.38% (p=0.000 n=10+10)
HashMapAcyclic-6 202 ± 0% 202 ± 0% ~ (all equal)
TailcfgNode-6 11.0 ± 0% 0.0 -100.00% (p=0.000 n=10+10)
Updates tailscale/corp#2130
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
2021-07-07 11:30:49 -07:00
3962744450
util/deephash: prevent infinite loop on map cycle
...
Fixes #2340
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
2021-07-07 10:57:46 -07:00
aceaa70b16
util/deephash: move funcs to methods
...
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
2021-07-07 08:17:18 -07:00
14f901da6d
util/deephash: fix sync.Pool usage
...
Whoops.
From yesterday's 9ae3bd0939
(not yet
used by anything, fortunately)
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
2021-07-05 22:21:44 -07:00
e0258ffd92
util/deephash: use keyed struct literal, fix vet
...
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
2021-07-05 21:31:30 -07:00
bf9f279768
util/deephash: optimize CPU a bit by by avoiding fmt in more places
...
name old time/op new time/op delta
Hash-6 179µs ± 5% 173µs ± 4% -3.12% (p=0.004 n=10+10)
HashMapAcyclic-6 115µs ± 3% 101µs ± 5% -11.51% (p=0.000 n=9+9)
TailcfgNode-6 30.8µs ± 4% 29.4µs ± 2% -4.51% (p=0.000 n=10+8)
name old alloc/op new alloc/op delta
Hash-6 3.60kB ± 0% 3.60kB ± 0% ~ (p=0.445 n=9+10)
HashMapAcyclic-6 2.53kB ± 0% 2.53kB ± 0% ~ (p=0.065 n=9+10)
TailcfgNode-6 528B ± 0% 528B ± 0% ~ (all equal)
name old allocs/op new allocs/op delta
Hash-6 84.0 ± 0% 84.0 ± 0% ~ (all equal)
HashMapAcyclic-6 202 ± 0% 202 ± 0% ~ (all equal)
TailcfgNode-6 11.0 ± 0% 11.0 ± 0% ~ (all equal)
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
2021-07-05 21:28:54 -07:00
58f2ef6085
util/deephash: add a benchmark and some benchmark data
...
No code changes.
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
2021-07-05 21:21:52 -07:00
9ae3bd0939
util/deephash: export a Hash func for use by the control plane
...
name old time/op new time/op delta
Hash-6 69.4µs ± 6% 68.4µs ± 4% ~ (p=0.286 n=9+9)
HashMapAcyclic-6 115µs ± 5% 115µs ± 4% ~ (p=1.000 n=10+10)
name old alloc/op new alloc/op delta
Hash-6 2.29kB ± 0% 1.88kB ± 0% -18.13% (p=0.000 n=10+10)
HashMapAcyclic-6 2.53kB ± 0% 2.53kB ± 0% ~ (all equal)
name old allocs/op new allocs/op delta
Hash-6 58.0 ± 0% 54.0 ± 0% -6.90% (p=0.000 n=10+10)
HashMapAcyclic-6 202 ± 0% 202 ± 0% ~ (all equal)
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com >
2021-07-05 11:41:44 -07:00
700badd8f8
util/deephash: move internal/deephash to util/deephash
...
No code changes. Just a minor package doc addition about lack of API
stability.
2021-07-02 21:33:02 -07:00