aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/hash_test.go
AgeCommit message (Collapse)Author
2022-04-27runtime: disable windowed Smhasher test on 32-bit systemsKeith Randall
This test tends to be flaky on 32-bit systems. There's not enough bits in the hash output, so we expect a nontrivial number of collisions, and it is often quite a bit higher than expected. Fixes #43130 Change-Id: If35413b7c45eed778a08b834dacf98009ceca840 Reviewed-on: https://go-review.googlesource.com/c/go/+/402456 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@google.com>
2021-12-13all: gofmt -w -r 'interface{} -> any' srcRuss Cox
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
2021-05-24cmd/compile: always include underlying type for map typesKeith Randall
This is a different fix for #37716. Should help make the fix for #46283 easier, since we will no longer need to keep compiler-generated hash functions and the runtime hash function in sync. Change-Id: I84cb93144e425dcd03afc552b5fbd0f2d2cc6d39 Reviewed-on: https://go-review.googlesource.com/c/go/+/322150 Trust: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2020-06-12runtime: raise alert threshold on window smhasher testKeith Randall
This alert is triggering occasionally. I've investigated the collisions that happen, and they all seem to be pairwise, so they are not a big deal. "pairwise" = when there are 32 collisions, it is two keys mapping to the same hash, 32 times, not 33 keys all mapping to the same hash. Add some t.Logf calls in case this comes back, which will help isolate the problem. Fixes #39352 Change-Id: I1749d7c8efd0afcf9024d8964d15bc0f58a86e4f Reviewed-on: https://go-review.googlesource.com/c/go/+/237718 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-03-10runtime: make typehash match compiler generated hashes exactlyKeith Randall
If typehash (used by reflect) does not match the built-in map's hash, then problems occur. If a map is built using reflect, and then assigned to a variable of map type, the hash function can change. That causes very bad things. This issue is rare. MapOf consults a cache of all types that occur in the binary before making a new one. To make a true new map type (with a hash function derived from typehash) that map type must not occur in the binary anywhere. But to cause the bug, we need a variable of that type in order to assign to it. The only way to make that work is to use a named map type for the variable, so it is distinct from the unnamed version that MapOf looks for. Fixes #37716 Change-Id: I3537bfceca8cbfa1af84202f432f3c06953fe0ed Reviewed-on: https://go-review.googlesource.com/c/go/+/222357 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
2019-01-03runtime: remove redundant slicingStepan Shabalin
In the twoNonZero function in hash_test, the buffer is sliced as [:] three times. This change deletes them. Change-Id: I0701d0c810b4f3e267f80133a0dcdb4ed81fe356 Reviewed-on: https://go-review.googlesource.com/c/156138 Reviewed-by: Keith Randall <khr@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2018-04-30all: skip unsupported tests for js/wasmRichard Musiol
The general policy for the current state of js/wasm is that it only has to support tests that are also supported by nacl. The test nilptr3.go makes assumptions about which nil checks can be removed. Since WebAssembly does not signal on reading a null pointer, all nil checks have to be explicit. Updates #18892 Change-Id: I06a687860b8d22ae26b1c391499c0f5183e4c485 Reviewed-on: https://go-review.googlesource.com/110096 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-08-28runtime: specialize memhash32 and memhash64Martin Möhrmann
AMD64 with AES support disabled: name old time/op new time/op delta MapPopulate/1 78.0ns ± 1% 75.5ns ± 1% -3.17% (p=0.000 n=10+9) MapPopulate/10 764ns ± 2% 673ns ± 2% -11.91% (p=0.000 n=10+10) MapPopulate/100 9.52µs ± 1% 8.54µs ± 1% -10.37% (p=0.000 n=8+10) MapPopulate/1000 116µs ± 2% 103µs ± 1% -10.40% (p=0.000 n=10+8) MapPopulate/10000 1.01ms ± 1% 0.90ms ± 1% -10.70% (p=0.000 n=10+10) MapPopulate/100000 9.81ms ± 1% 8.67ms ± 2% -11.54% (p=0.000 n=10+10) 386 with AES support disabled: name old time/op new time/op delta MapPopulate/1 95.3ns ± 1% 90.6ns ± 1% -4.95% (p=0.000 n=10+9) MapPopulate/10 983ns ± 2% 912ns ± 1% -7.18% (p=0.000 n=10+10) MapPopulate/100 11.9µs ± 2% 11.2µs ± 1% -6.01% (p=0.000 n=10+10) MapPopulate/1000 140µs ± 1% 131µs ± 1% -6.19% (p=0.000 n=10+10) MapPopulate/10000 1.26ms ± 2% 1.18ms ± 1% -5.93% (p=0.000 n=9+10) MapPopulate/100000 12.1ms ± 2% 11.4ms ± 1% -5.48% (p=0.000 n=10+10) Fixes #21539 Change-Id: Ice128c947c9a6a294800d6a5250d82045eb70b55 Reviewed-on: https://go-review.googlesource.com/59352 Run-TryBot: Martin Möhrmann <moehrmann@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2016-09-24runtime: remove TestCollisions from -shortKeith Randall
Takes a bit too long to run it all the time. Fixes #17217 Update #17104 Change-Id: I4802190ea16ee0f436a7f95b093ea0f995f5b11d Reviewed-on: https://go-review.googlesource.com/29751 Run-TryBot: Keith Randall <khr@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-06-11runtime: aeshash, xor seed in earlierKeith Randall
Instead of doing: x = input one round of aes on x x ^= seed two rounds of aes on x Do: x = input x ^= seed three rounds of aes on x This change provides some additional seed-dependent scrambling which should help prevent collisions. Change-Id: I02c774d09c2eb6917cf861513816a1024a9b65d7 Reviewed-on: https://go-review.googlesource.com/23577 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-18runtime: add spaceKeith Randall
Missed this in review of 20812 Change-Id: I01e220499dcd58e1a7205e2a577dd9630a8b7174 Reviewed-on: https://go-review.googlesource.com/20819 Reviewed-by: Keith Randall <khr@golang.org>
2016-03-18runtime: use unaligned loads on ppc64Keith Randall
benchmark old ns/op new ns/op delta BenchmarkAlignedLoad-160 8.67 7.42 -14.42% BenchmarkUnalignedLoad-160 8.63 7.37 -14.60% Change-Id: Id4609d7b4038c4d2ec332efc4fe6f1adfb61b82b Reviewed-on: https://go-review.googlesource.com/20812 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-02all: single space after period.Brad Fitzpatrick
The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-01all: make copyright headers consistent with one space after periodBrad Fitzpatrick
This is a subset of https://golang.org/cl/20022 with only the copyright header lines, so the next CL will be smaller and more reviewable. Go policy has been single space after periods in comments for some time. The copyright header template at: https://golang.org/doc/contribute.html#copyright also uses a single space. Make them all consistent. Change-Id: Icc26c6b8495c3820da6b171ca96a74701b4a01b0 Reviewed-on: https://go-review.googlesource.com/20111 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-09-15runtime: fix aeshash of empty stringKeith Randall
Aeshash currently computes the hash of the empty string as hash("", seed) = seed. This is bad because the hash of a compound object with empty strings in it doesn't include information about where those empty strings were. For instance [2]string{"", "foo"} and [2]string{"foo", ""} might get the same hash. Fix this by returning a scrambled seed instead of the seed itself. With this fix, we can remove the scrambling done by the generated array hash routines. The test also rejects hash("", seed) = 0, if we ever thought it would be a good idea to try that. The fallback hash is already OK in this regard. Change-Id: Iaedbaa5be8d6a246dc7e9383d795000e0f562037 Reviewed-on: https://go-review.googlesource.com/14129 Reviewed-by: jcd . <jcd@golang.org>
2015-08-31runtime: soften up hash checks a bitKeith Randall
The hash tests generate occasional failures, quiet them some more. In particular we can get 1 collision when the expected number is .001 or so. That shouldn't be a dealbreaker. Fixes #12311 Change-Id: I784e91b5d21f4f1f166dc51bde2d1cd3a7a3bfea Reviewed-on: https://go-review.googlesource.com/13902 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2014-12-22runtime: a better fallback hashKeith Randall
For arm and powerpc, as well as x86 without aes instructions. Contains a mixture of ideas from cityhash and xxhash. Compared to our old fallback on ARM, it's ~no slower on small objects and up to ~50% faster on large objects. More importantly, it is a much better hash function and thus has less chance of bad behavior. Fixes #8737 benchmark old ns/op new ns/op delta BenchmarkHash5 173 181 +4.62% BenchmarkHash16 252 212 -15.87% BenchmarkHash64 575 419 -27.13% BenchmarkHash1024 7173 3995 -44.31% BenchmarkHash65536 516940 313173 -39.42% BenchmarkHashStringSpeed 300 279 -7.00% BenchmarkHashBytesSpeed 478 424 -11.30% BenchmarkHashInt32Speed 217 207 -4.61% BenchmarkHashInt64Speed 262 231 -11.83% BenchmarkHashStringArraySpeed 609 631 +3.61% Change-Id: I0a9335028f32b10ad484966e3019987973afd3eb Reviewed-on: https://go-review.googlesource.com/1360 Reviewed-by: Russ Cox <rsc@golang.org>
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.