-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
x/tools/go/types/typeutil: gut Hasher #69407
Comments
Change https://go.dev/cl/612496 mentions this issue: |
#54670 was accepted. Once it is available, can we use that? |
@timothy-king do you mean to use Comparable for hashPtr, rather than relying on a non-moving GC? |
maphash.Comparable does the same thing as our code (reflect.Value.Pointer). The only difference is that, being std code, it is morally permitted to assume a non-moving GC, but once the updated #67161 lands, we can use (Discussion about Comparable here #54670 (comment).) |
Change https://go.dev/cl/648895 mentions this issue: |
Shifting by 32 on an uintptr causes vet's check for shifts that equal or exceed the width of the integer to trigger on 32-bit architectures. For example, on 386: $ GOARCH=386 GOOS=linux go vet golang.org/x/tools/go/types/typeutil # golang.org/x/tools/go/types/typeutil go/types/typeutil/map.go:393:24: hash (32 bits) too small for shift of 32 Because this package is vendored into the main Go tree, and go test has a special case to turn on all vet checks there, the finding is promoted to an error (even if the code is otherwise harmless). Fix it. For golang/go#69407. For golang/go#36905. Change-Id: Ib8bf981bbe338db4ba8e9b7add0b373acae7338d Cq-Include-Trybots: luci.golang.try:x_tools-gotip-linux-386-longtest,x_tools-gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/tools/+/648895 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
Thinking about #67161, I wanted to know whether the the new API should include Hasher. It complicates the API because it turns reads (lookups in typeutil.Map) into writes (memoization of hash values). Is it an effective optimization, or does it increase memory contention (and potentially the need for locking)?
I gutted its implementation, removing both memoization maps, and simplifying the implementation of Hasher.hashPtr to just
reflect.ValueOf(ptr).Pointer()
(which assumes a non-moving GC) and Hasher.hashTypeParam to a hash of t.Index(), making Hasher a stateless empty struct. Then I ran BenchmarkRTA, modified to analyze all of gopls, not just net/http.The results:
It is slightly faster and has lower variance. Whatever problems a stateful Hasher once solved, we have no further need for it.
Let's make it an empty struct, and disregard it when considering #67161.
@timothy-king @findleyr
The text was updated successfully, but these errors were encountered: