ddd8bc1b07
LookupFieldOrMethod appears as a hotspot when benchmarking gopls' auto-completion. In particular, instanceLookup.add was allocating in the common case of structs with no embedding. This is easily fixed, by using a small array in front of the map inside of instanceLookup. Do this, and additionally add a microbenchmark. The benchmark improvement is significant: name old time/op new time/op delta LookupFieldOrMethod-12 388µs ± 6% 154µs ± 3% -60.36% (p=0.000 n=10+10) name old alloc/op new alloc/op delta LookupFieldOrMethod-12 152kB ± 0% 2kB ± 0% -98.77% (p=0.000 n=9+10) name old allocs/op new allocs/op delta LookupFieldOrMethod-12 1.41k ± 0% 0.07k ± 0% -95.38% (p=0.000 n=10+10) It should also be noted that instanceLookup is used elsewhere, in particular by validType. In those contexts, the scope is not just the current type but the entire package, and so the newly added buffer is likely to simply cause extra Identical checks. Nevertheless, those checks are cheap, and on balance the improved LookupFieldOrMethod performance leads overall to improved type-checking performance. Standard library benchmark results varied by package, but type checking speed for many packages improved by ~5%, with allocations improved by ~10%. If this weren't the case we could let the caller control the buffer size, but that optimization doesn't seem necessary at this time. For example: Check/http/funcbodies/noinfo-12 71.5ms ± 4% 67.3ms ± 2% -5.90% (p=0.000 n=20+20) Check/http/funcbodies/noinfo-12 244k ± 0% 219k ± 0% -10.36% (p=0.000 n=19+19) Updates golang/go#53992 Change-Id: I10b6deb3819ab562dbbe1913f12b977cf956dd50 Reviewed-on: https://go-review.googlesource.com/c/go/+/423935 Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> |
||
---|---|---|
.github | ||
api | ||
doc | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
codereview.cfg | ||
CONTRIBUTING.md | ||
LICENSE | ||
PATENTS | ||
README.md | ||
SECURITY.md |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
Gopher image by Renee French, licensed under Creative Commons 3.0 Attributions license.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
Download and Install
Binary Distributions
Official binary distributions are available at https://go.dev/dl/.
After downloading a binary release, visit https://go.dev/doc/install for installation instructions.
Install From Source
If a binary distribution is not available for your combination of operating system and architecture, visit https://go.dev/doc/install/source for source installation instructions.
Contributing
Go is the work of thousands of contributors. We appreciate your help!
To contribute, please read the contribution guidelines at https://go.dev/doc/contribute.
Note that the Go project uses the issue tracker for bug reports and proposals only. See https://go.dev/wiki/Questions for a list of places to ask questions about the Go language.