1
0
mirror of https://github.com/golang/go synced 2024-11-17 05:14:56 -07:00
Commit Graph

54098 Commits

Author SHA1 Message Date
Wayne Zuo
629c0b3a6e cmd/compile: make encoding/binary appends cheaper to inline
Go 1.19 introduce new append-like APIs in package encoding/binary, this
change teaches the inliner to treat calls to these methods as cheap, so
that code using them will be more inlineable.

Updates #42958

Change-Id: Ie3dd4906e285430f435bdedbf8a11fdffce9302d
Reviewed-on: https://go-review.googlesource.com/c/go/+/431015
Auto-Submit: Keith Randall <khr@golang.org>
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
Reviewed-by: Keith Randall <khr@google.com>
2022-09-15 21:05:02 +00:00
Wayne Zuo
5760fde4df cmd/compile: avoid sign extension after word arithmetic on riscv64
These instructions already do sign extension on output, so we can get rid of it.

Note: (MOVWreg (MULW x y)) may araise from divisions by constant,
generic rules replace them with multiply and may produce (Rsh32x64 (Mul32 _ _) _).

Change-Id: I41bc9b519e38bc6027311de604dadb962cd0bbf4
Reviewed-on: https://go-review.googlesource.com/c/go/+/429757
Run-TryBot: Wayne Zuo <wdvxdr@golangcn.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
2022-09-15 21:04:37 +00:00
cuiweixie
501df45199 cmd/go: use strings.Builder
Change-Id: I0db93b7bdcd622ce9e23df183de4737744e6d6ea
Reviewed-on: https://go-review.googlesource.com/c/go/+/428294
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: xie cui <523516579@qq.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Run-TryBot: Jenny Rakoczy <jenny@golang.org>
2022-09-15 21:04:34 +00:00
Tobias Klauser
7722b3c86d internal/syscall/unix: remove superfluous var declarations in {Unlink,Open}at
Change-Id: Id58e3aebf325433768675523bf34c0b7e0e34aea
Reviewed-on: https://go-review.googlesource.com/c/go/+/431235
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-15 21:04:12 +00:00
Joe Tsai
a29739145d compress/flate: update NewReader documentation
Calling close is no longer necessary.
It was was originally necessary to cleanup goroutines
spawned to decompress the stream.
This has not been the case since CL 4548079.

Update the documentation to mention how it handles trailing data
after the end of the DEFLATE stream.

Change-Id: Ieacba264230560713b7b8d604665223fd096f4ec
Reviewed-on: https://go-review.googlesource.com/c/go/+/430377
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
2022-09-15 20:02:32 +00:00
Joel Sing
44ad662a49 runtime: optimise memclrNoHeapPointers on riscv64
Implement a more optimised memclrNoHeapPointers on riscv64, where up
to 64 bytes are zeroed per loop after achieving alignment.

name                     old time/op    new time/op     delta
Memclr/5-4                 53.1ns _ 0%     37.0ns _ 4%   -30.37%  (p=0.002 n=3+3)
Memclr/16-4                42.3ns _ 0%     34.8ns _ 0%   -17.81%  (p=0.000 n=3+3)
Memclr/64-4                67.8ns _ 0%     44.0ns _ 1%   -35.09%  (p=0.000 n=3+3)
Memclr/256-4                185ns _ 0%       78ns _ 1%   -57.52%  (p=0.000 n=3+3)
Memclr/4096-4              2.50_s _ 1%     0.76_s _ 1%   -69.72%  (p=0.000 n=3+3)
Memclr/65536-4             55.6_s _ 0%     31.4_s _ 0%   -43.56%  (p=0.000 n=3+3)
Memclr/1M-4                1.15ms _ 0%     0.72ms _ 1%   -37.14%  (p=0.000 n=3+3)
Memclr/4M-4                12.1ms _ 3%     10.1ms _ 0%   -16.51%  (p=0.007 n=3+3)
Memclr/8M-4                25.2ms _ 1%     21.5ms _ 0%   -14.75%  (p=0.001 n=3+3)
Memclr/16M-4               52.8ms _ 5%     43.4ms _ 0%   -17.95%  (p=0.019 n=3+3)
Memclr/64M-4                202ms _ 1%      173ms _ 0%   -14.42%  (p=0.001 n=3+3)
MemclrRange/1K_2K-4        54.0_s _ 1%     22.0_s _ 0%   -59.26%  (p=0.000 n=3+3)
MemclrRange/2K_8K-4         176_s _ 1%       64_s _ 1%   -63.77%  (p=0.000 n=3+3)
MemclrRange/4K_16K-4        172_s _ 6%       60_s _ 0%   -65.38%  (p=0.002 n=3+3)
MemclrRange/160K_228K-4    1.54ms _ 1%     0.91ms _ 0%   -40.60%  (p=0.000 n=3+3)

name                     old speed      new speed       delta
Memclr/5-4               94.1MB/s _ 0%  135.3MB/s _ 4%   +43.70%  (p=0.004 n=3+3)
Memclr/16-4               378MB/s _ 0%    460MB/s _ 0%   +21.67%  (p=0.000 n=3+3)
Memclr/64-4               943MB/s _ 0%   1454MB/s _ 1%   +54.07%  (p=0.000 n=3+3)
Memclr/256-4             1.39GB/s _ 0%   3.26GB/s _ 1%  +135.38%  (p=0.000 n=3+3)
Memclr/4096-4            1.64GB/s _ 1%   5.41GB/s _ 1%  +230.28%  (p=0.000 n=3+3)
Memclr/65536-4           1.18GB/s _ 0%   2.09GB/s _ 0%   +77.19%  (p=0.000 n=3+3)
Memclr/1M-4               914MB/s _ 0%   1454MB/s _ 1%   +59.08%  (p=0.000 n=3+3)
Memclr/4M-4               346MB/s _ 3%    415MB/s _ 0%   +19.73%  (p=0.004 n=3+3)
Memclr/8M-4               332MB/s _ 1%    390MB/s _ 0%   +17.29%  (p=0.000 n=3+3)
Memclr/16M-4              318MB/s _ 5%    387MB/s _ 0%   +21.72%  (p=0.013 n=3+3)
Memclr/64M-4              333MB/s _ 1%    389MB/s _ 0%   +16.84%  (p=0.001 n=3+3)
MemclrRange/1K_2K-4      1.78GB/s _ 1%   4.36GB/s _ 0%  +145.48%  (p=0.000 n=3+3)
MemclrRange/2K_8K-4      1.89GB/s _ 1%   5.22GB/s _ 1%  +176.03%  (p=0.000 n=3+3)
MemclrRange/4K_16K-4     1.88GB/s _ 5%   5.42GB/s _ 0%  +188.40%  (p=0.000 n=3+3)
MemclrRange/160K_228K-4  1.08GB/s _ 1%   1.82GB/s _ 0%   +68.35%  (p=0.000 n=3+3)

Change-Id: Ide566f148f890f70217ed08fd472ee5893d3511c
Reviewed-on: https://go-review.googlesource.com/c/go/+/426255
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Joel Sing <joel@sing.id.au>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Meng Zhuo <mzh@golangcn.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-09-15 19:29:39 +00:00
Cherry Mui
5231ba2f05 cmd/link: stop passing -pagezero_size to darwin linker
We added -pagezero_size in CL 72730, where it was intented for iOS.
The current code passes it only on macOS/AMD64 instead. It is not
really necessary there. Also, the new darwin linker starts to emit
a warning about deprecation of the flag. Stop passing it.

For #54482.

Change-Id: If9db7a1645c37d4284e48f075856912df8d8c1a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/430936
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
2022-09-15 14:57:53 +00:00
Keith Randall
e665de2861 runtime/race: introduce subarch versioning of race syso
Allow us to select a race .syso file based on subarch values.

Note that this doesn't actually change the syso used. This CL
just moves things around in preparation for adding v3-specific
versions in future CLs.

Change-Id: I14e3c273a7c6f07b13b22193b7a851ea94c765cb
Reviewed-on: https://go-review.googlesource.com/c/go/+/424034
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Keith Randall <khr@golang.org>
2022-09-15 14:08:12 +00:00
Tobias Klauser
7c3284401f cmd, syscall: use syscall.Mmap on solaris for Go ≥ 1.20
CL 413374 added syscall.Mmap on solaris. Use it in cmd/compile and
cmd/link if the bootstrap toolchain is Go ≥ 1.20.

For #52875
For #54265

Change-Id: I9a0534bf97926eecf0c6f1f9218e855344ba158f
Reviewed-on: https://go-review.googlesource.com/c/go/+/430496
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
2022-09-15 06:23:50 +00:00
Kévin Dunglas
972870da11 net/http/httputil: forward 1xx responses in ReverseProxy
Support for 1xx responses has recently been merged in
net/http (CL 269997).

As discussed in this CL
(https://go-review.googlesource.com/c/go/+/269997/comments/1ff70bef_c25a829a),
support for forwarding 1xx responses in ReverseProxy has been extracted
in this separate patch.

According to RFC 7231, "a proxy MUST forward 1xx responses unless the
proxy itself requested the generation of the 1xx response".
Consequently, all received 1xx responses are automatically forwarded as long as the
underlying transport supports ClientTrace.Got1xxResponse.

Fixes #26088
Fixes #51914

Change-Id: I3a35ea023b798bfe56b7fb8696d5a49695229cfd
GitHub-Last-Rev: dab8a461fb
GitHub-Pull-Request: golang/go#53164
Reviewed-on: https://go-review.googlesource.com/c/go/+/409536
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Rhys Hiltner <rhys@justin.tv>
Run-TryBot: hopehook <hopehook@golangcn.org>
2022-09-14 23:59:32 +00:00
Emmanuel T Odeke
4baa486983 all: remove unnecessary allocations from w.WriteString(fmt.Sprint*(...)) by fmt.Fprint*(w, ...)
Noticed in a manual audit from a customer codebase that the pattern

    w.WriteString(fmt.Sprint*(args...))

was less efficient and in most cases we can just invoke:

    fmt.Fprint*(w, args...)

and from the simple benchmarks we can see quick wins in all dimensions:

$ benchstat before.txt after.txt
name            old time/op    new time/op    delta
DetailString-8    5.48µs ±23%    4.40µs ±11%  -19.79%  (p=0.000 n=20+17)

name            old alloc/op   new alloc/op   delta
DetailString-8    2.63kB ± 0%    2.11kB ± 0%  -19.76%  (p=0.000 n=20+20)

name            old allocs/op  new allocs/op  delta
DetailString-8      63.0 ± 0%      50.0 ± 0%  -20.63%  (p=0.000 n=20+20)

Change-Id: I47a2827cd34d6b92644900b1bd5f4c0a3287bdb1
Reviewed-on: https://go-review.googlesource.com/c/go/+/429861
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
2022-09-14 16:11:21 +00:00
Ali Yousefi Sabzevar
a7e9a379e9 go/types, types2: improve readability of _InvalidUntypedConversion docs
Remove an unnecessary 'an' from errorcodes.go.

Change-Id: Iabe8ce479077cbfff936d57c788a9b39d7e5b34e
Reviewed-on: https://go-review.googlesource.com/c/go/+/430495
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
2022-09-14 15:19:55 +00:00
Anuraag Agrawal
9503bcae2b strings: reuse the input string for Repeat count of 1
The existing implementation allocates a new string even when the
count is 1, where we know the output is the same as the input.
While we wouldn't expect a count of 1 for hardcoded values of the
parameter, it is expected when the parameter is computed based on
a different value (e.g., the length of a input slice).

name            old time/op  new time/op  delta
Repeat/5x0-10   2.03ns ± 0%  2.02ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/5x1-10   13.7ns ± 0%   2.0ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/5x2-10   18.2ns ± 0%  18.1ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/5x6-10   27.0ns ± 0%  27.0ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/10x0-10  2.02ns ± 0%  2.02ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/10x1-10  16.1ns ± 0%   2.0ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/10x2-10  20.8ns ± 0%  20.9ns ± 0%   ~     (p=1.000 n=1+1)
Repeat/10x6-10  29.2ns ± 0%  29.4ns ± 0%   ~     (p=1.000 n=1+1)

Change-Id: I48e08e08f8f6d6914d62b3d6a61d563d637bec59
GitHub-Last-Rev: 068f58e08b
GitHub-Pull-Request: golang/go#53321
Reviewed-on: https://go-review.googlesource.com/c/go/+/411477
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Keith Randall <khr@google.com>
2022-09-14 14:56:07 +00:00
Ian Lance Taylor
d60e51e353 go/build: remove unnecessary copies of package variables
These variables never change, we don't need second copies of them.

Also rename bPlusBuild to plusBuild, since it is the only remaining
variable with a "b" prefix.

Change-Id: I97089b001d23e9b0f2096e19d9ceed7a9bbb377d
Reviewed-on: https://go-review.googlesource.com/c/go/+/429636
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-14 14:52:52 +00:00
Bryan C. Mills
72e07dbee0 cmd/go/testdata/script: remove reference to fixed issue
The issue referenced in work_prune.txt was fixed in CL 362754, but we
forgot to update the TODO or mark the issue as fixed in the commit
message.

Updates #48331.

Change-Id: Id2115e496aeaef275dd3c8d32c5c5564e6addb07
Reviewed-on: https://go-review.googlesource.com/c/go/+/425485
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2022-09-14 14:30:53 +00:00
Ian Lance Taylor
ebbaba2813 path/filepath: document that WalkDir uses OS paths
Fixes #52812

Change-Id: Idb70d0540bbf9ecdc64293c62a23f07ee3be883c
Reviewed-on: https://go-review.googlesource.com/c/go/+/405615
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Caleb Spare <cespare@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-14 14:19:13 +00:00
Tobias Klauser
244127e4b4 all: move //go:build lines below copyright notice
Change-Id: Ib6196f01b1927ea8a84c095f445320f03a514dd1
Reviewed-on: https://go-review.googlesource.com/c/go/+/429796
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-14 14:17:04 +00:00
jiepeng
585c438615 cmd/go/internal/vcs: replace [A-Za-z0-9_] with \w in regexps
Change-Id: Ibcc7dbb528585b019ff1b743792a52f43a4c2233
GitHub-Last-Rev: e907fb00e3
GitHub-Pull-Request: golang/go#54882
Reviewed-on: https://go-review.googlesource.com/c/go/+/428535
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-14 11:32:35 +00:00
Cherry Mui
a813be86df cmd/compile: don't use R25 as input for LoweredMove on ARM64
The rule uses R25 as a scratch register. If the input is R25 it
will be clobbered on the way, causing wrong result.

Change-Id: I464eadbdef0f3a5e90f9ef8c818393baa4335b87
Reviewed-on: https://go-review.googlesource.com/c/go/+/430015
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Eric Fang <eric.fang@arm.com>
2022-09-13 17:43:40 +00:00
cui fliter
f78efc0178 runtime: convert timer.status to atomic type
For #53821

Change-Id: I7cb6a16626964d5023b96609d9921bfe4a679d8f
GitHub-Last-Rev: ddfce125be
GitHub-Pull-Request: golang/go#54865
Reviewed-on: https://go-review.googlesource.com/c/go/+/428196
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-13 17:41:56 +00:00
Vladimir Varankin
39b31a3eb2 net/http: make DefaultTransport docs about HTTP proxy consistent
The changes improve the documentation for DefaultTransport, making
the style with how the HTTP proxy environment variables are being
referred to, consistent with the rest of the project's
documentation.

Also mention HTTPS_PROXY environment variables, as suggested in #32649.

Change-Id: I4e6b49881d7b30b5a0d4699531fa7c2929fc49f7
GitHub-Last-Rev: 2fc751937b
GitHub-Pull-Request: golang/go#54996
Reviewed-on: https://go-review.googlesource.com/c/go/+/430135
Reviewed-by: Damien Neil <dneil@google.com>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Damien Neil <dneil@google.com>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-13 17:41:36 +00:00
Cuong Manh Le
5bbee7a095 reflect: move benchmarks to its own file
all_test.go is quite big, so let it contain tests only.

Change-Id: I5003db4a8b1e2384ea8470f5e89e1c26d61d10ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/429759
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-09-13 17:41:16 +00:00
Leonard Wang
6f7c9ea855 runtime: set userForced while holding gcsema
Fixes #52515

Change-Id: If10068a97733daf61aba72da5ed3935db8eed8b9
Reviewed-on: https://go-review.googlesource.com/c/go/+/401776
Reviewed-by: hopehook <hopehook@golangcn.org>
Run-TryBot: hopehook <hopehook@golangcn.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-13 17:41:06 +00:00
Cuong Manh Le
242adb784c syscall: simplify unsafe.Slice usage
Same as CL 429915.

Change-Id: I83f4d3bd980294d5bae387d875368b069be2d91a
Reviewed-on: https://go-review.googlesource.com/c/go/+/429955
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: hopehook <hopehook@golangcn.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
2022-09-13 17:40:53 +00:00
Joel Sing
e084d84420 cmd/internal/objabi: declare HeadType String on a non-pointer receiver
objabi.HeadType is typically used as a non-pointer type, however the String function
is declared on a pointer receiver. This means that in most cases its integer value
is printed, rather than the value from the String function.

Change-Id: I3d28d9680e88a714bc1152ed5e1df4ac43d7a33f
Reviewed-on: https://go-review.googlesource.com/c/go/+/430556
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
2022-09-13 17:39:55 +00:00
cui fliter
09f3ff174c strings: add a test case of growLen is negative
Before committing,  the test coverage of strings/builder.go is 97.4%
After committing,  the test coverage of strings/builder.go is 100%

Change-Id: I22643b1c4632b5ca7ef98362f32bb85faae80bad
GitHub-Last-Rev: 2a55ca3e33
GitHub-Pull-Request: golang/go#55004
Reviewed-on: https://go-review.googlesource.com/c/go/+/430156
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
2022-09-13 17:39:52 +00:00
Joel Sing
77420fa119 cmd/link: generate an error if the entry symbol cannot be found
If the entry symbol cannot be found (for example, a new port is being brought
up and no rt0 code has been provided), the linker will currently panic. Rather
than panicing, generate an error that aids in debugging:

	missing entry symbol "_rt0_arm64_openbsd"

Change-Id: I9cc38eaab48f730d596ca7fa9e9e3d68250ae4d3
Reviewed-on: https://go-review.googlesource.com/c/go/+/430555
Auto-Submit: Jenny Rakoczy <jenny@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
2022-09-13 17:39:33 +00:00
Joe Tsai
f7396aaea0 time: optimize Parse for RFC3339 and RFC3339Nano
RFC 3339 is the most common time representation,
being used in an overwhelming 57.3% of all specified formats,
while the next competitor only holds 7.5% usage.
Specially optimize parsing to handle the RFC 3339 format.
To reduce the complexity of error checking,
parseRFC3339 simply returns a bool indicating parsing success.
It leaves error handling to the general parse path.

To assist in fuzzing, the internal parse function was left unmodified
so that we could test that parseRFC3339 and parse agree with each other.

Performance:

	name             old time/op  new time/op  delta
	ParseRFC3339UTC  112ns ± 1%   37ns ± 1%    -67.37%  (p=0.000 n=9+9)
	ParseRFC3339TZ   259ns ± 2%   67ns ± 1%    -73.92%  (p=0.000 n=10+9)

Credit goes to Amarjeet Anand for a prior CL attemping to optimize this.
See CL 425014.

Fixes #54093

Change-Id: I14f4e8c52b092d44ceef6863f261842ed7e83f4c
Reviewed-on: https://go-review.googlesource.com/c/go/+/425197
Reviewed-by: Rob Pike <r@golang.org>
Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
2022-09-13 17:35:58 +00:00
Cuong Manh Le
7ffbcd1987 runtime: replace stringStruct with unsafe.String where appropriate
Simplify the code a bit, no significant performance changes.

name                             old time/op    new time/op    delta
HashStringSpeed-8                  9.64ns ±11%    8.91ns ± 9%   -7.60%  (p=0.007 n=10+10)
HashStringArraySpeed-8             19.8ns ± 3%    19.5ns ± 2%     ~     (p=0.085 n=10+10)
MapStringKeysEight_16-8            10.7ns ± 3%    10.2ns ± 2%   -4.48%  (p=0.000 n=10+10)
MapStringKeysEight_32-8            8.89ns ± 3%    8.71ns ± 3%     ~     (p=0.082 n=9+10)
MapStringKeysEight_64-8            8.84ns ± 2%    8.60ns ± 3%   -2.73%  (p=0.004 n=9+10)
MapStringKeysEight_1M-8            8.90ns ± 3%    8.62ns ± 3%   -3.15%  (p=0.000 n=10+10)
MapStringConversion/32/simple-8    8.62ns ± 3%    8.61ns ± 2%     ~     (p=0.895 n=10+10)
MapStringConversion/32/struct-8    8.53ns ± 2%    8.63ns ± 2%     ~     (p=0.123 n=10+10)
MapStringConversion/32/array-8     8.54ns ± 2%    8.50ns ± 1%     ~     (p=0.590 n=9+9)
MapStringConversion/64/simple-8    8.44ns ± 2%    8.38ns ± 2%     ~     (p=0.353 n=10+10)
MapStringConversion/64/struct-8    8.41ns ± 2%    8.48ns ± 2%     ~     (p=0.143 n=10+10)
MapStringConversion/64/array-8     8.42ns ± 2%    8.44ns ± 2%     ~     (p=0.739 n=10+10)
MapInterfaceString-8               13.6ns ±26%    13.6ns ±20%     ~     (p=0.736 n=10+9)
AppendGrowString-8                 38.9ms ± 9%    40.2ms ±13%     ~     (p=0.481 n=10+10)
CompareStringEqual-8               3.03ns ± 2%    2.86ns ± 3%   -5.58%  (p=0.000 n=10+10)
CompareStringIdentical-8           1.20ns ± 3%    1.01ns ± 4%  -16.16%  (p=0.000 n=10+10)
CompareStringSameLength-8          2.11ns ± 3%    1.85ns ± 3%  -12.33%  (p=0.000 n=10+10)
CompareStringDifferentLength-8     0.30ns ± 0%    0.30ns ± 0%     ~     (p=0.508 n=10+9)
CompareStringBigUnaligned-8        43.0µs ± 1%    42.8µs ± 2%     ~     (p=0.165 n=10+10)
CompareStringBig-8                 43.2µs ± 2%    43.4µs ± 2%     ~     (p=0.661 n=9+10)
ConcatStringAndBytes-8             15.1ns ± 1%    14.9ns ± 1%   -1.57%  (p=0.001 n=8+10)
SliceByteToString/1-8              2.45ns ± 2%    2.39ns ± 2%   -2.64%  (p=0.000 n=10+10)
SliceByteToString/2-8              10.9ns ± 2%    10.8ns ± 4%     ~     (p=0.060 n=10+10)
SliceByteToString/4-8              11.9ns ± 0%    11.8ns ± 1%   -0.97%  (p=0.000 n=8+8)
SliceByteToString/8-8              13.9ns ± 1%    13.9ns ± 1%   +0.57%  (p=0.009 n=9+9)
SliceByteToString/16-8             18.0ns ± 3%    18.6ns ± 5%   +2.78%  (p=0.001 n=9+10)
SliceByteToString/32-8             20.1ns ± 3%    20.5ns ± 5%   +2.10%  (p=0.034 n=10+10)
SliceByteToString/64-8             24.3ns ± 3%    24.9ns ± 3%   +2.28%  (p=0.001 n=9+10)
SliceByteToString/128-8            33.8ns ± 1%    34.5ns ± 4%     ~     (p=0.264 n=8+10)

Updates #54854

Change-Id: I7ce57a92c5f590fa8cb31a48969d281147eb05f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/428759
Reviewed-by: hopehook <hopehook@golangcn.org>
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-13 16:42:28 +00:00
Tobias Klauser
d36466fe2a cmd/link/internal/ld, syscall: use libc based msync on darwin for Go ≥ 1.20
Direct syscalls should no longer be used on darwin. Instead, directly
call libc's msync when using Go ≥ 1.20 for bootstrap.

For #54265

Change-Id: Ie3f1e6ccd1a06e7f0ddd88cdef5067393a69e8db
Reviewed-on: https://go-review.googlesource.com/c/go/+/430336
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2022-09-13 15:50:02 +00:00
Tobias Klauser
8df21a7802 cmd/link/internal/ld: drop Go 1.12 compatibility on darwin
Go 1.17 is the minimum required version for bootstrap as of Go 1.20.
Also, the package no longer builds with Go 1.12 used for bootstrap.
Thus, drop the Go 1.12 compatibility and used linkname unconditionally.

For #44505

Change-Id: Ic160aba4a33d580987b4633a3db03a025804d090
Reviewed-on: https://go-review.googlesource.com/c/go/+/430335
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2022-09-13 15:49:37 +00:00
Robert Griesemer
dad2966a83 go/types, types2: don't print function parameter names when showing type differences
Add a new flag 'paramNames' to typeWriter struct to control whether
function parameter names are written or not (set by default). Unset
it when we want the function signature w/o parameter names, e.g. when
showing two signatures that are not identical. This makes is much
easier to see the typw differences in the error message.

To avoid needing to provide yet another (rarely used) boolean parameter
to typeString, remove that function in favor of setting the paramNames
flag explicitly. Adjust the code in errors.go that used typeString; the
resulting code is also more efficient (fewer bytes.Buffer allocations).

While at it, rename the typeWriter 'debug' field to 'tpSubscripts'
because that is what it controls.

Add test case and adjusted existing expected output for existing tests.

Fixes #54942.

Change-Id: I625eae30c403c39ce89951b8ea6214d783c92c75
Reviewed-on: https://go-review.googlesource.com/c/go/+/430416
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
2022-09-13 12:58:04 +00:00
Robert Griesemer
c7a0b15659 go/types, types2: consistently use _UnsupportedFeature error code
Change-Id: Ie880871bb855e1c1f6e543508bdc7dd415451ba3
Reviewed-on: https://go-review.googlesource.com/c/go/+/429735
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
2022-09-13 12:38:14 +00:00
Robert Griesemer
f4a587ba6e types2: provide error codes to error reporting
This CL adds a suitable error code to every error reporting,
matching what go/types already does.

For now, the error codes are not progagated through the API,
but eventually they will be available to clients.

Also, for now the errorcodes.go file is a 1:1 copy (with
adjusted package name) of go/types/errorcodes.go.
A subsequent CL will factor out this file.

In contrast to go/types, for errors due to incorrect Go version,
the error code is always _UnsupportedFeature. In go/types, the
error sometimes is related to the specific operation.

Change-Id: I18771bc3d00bbdbf6d705bf25f2aea3c3d977b1c
Reviewed-on: https://go-review.googlesource.com/c/go/+/429355
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
2022-09-13 12:37:11 +00:00
Cuong Manh Le
54182ff54a internal/syscall/windows: simplify unsafe.Slice usage
CL 428780 used unsafe.Slice instead of unsafeheader for simplifiying the
code. However, it can be even simpler, since "p" is already a *uin16,
the unsafe cast is not necessary.

Change-Id: Idc492b73518637997e85c0b33f8591bd19b7929f
Reviewed-on: https://go-review.googlesource.com/c/go/+/429915
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-09-09 20:29:05 +00:00
cuiweixie
59ba97bf3b cmd/go: record the -buildmode flag in debug.BuildInfo
Fixes #53856

Change-Id: Ib533e9fbe063b74c81f6512464a4dac5e2af0ccc
GitHub-Last-Rev: c2ae8d6f75
GitHub-Pull-Request: golang/go#54218
Reviewed-on: https://go-review.googlesource.com/c/go/+/420937
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: xie cui <523516579@qq.com>
2022-09-09 20:25:35 +00:00
cui fliter
b244b89d56 net/http: convert allowQuerySemicolonsInUse to atomic type
For #53821

Change-Id: I135783bd5472011f6a74d2f5ee34ce96ff49ad2b
GitHub-Last-Rev: 4da2d67ff3
GitHub-Pull-Request: golang/go#54863
Reviewed-on: https://go-review.googlesource.com/c/go/+/428336
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
2022-09-09 18:42:57 +00:00
Cuong Manh Le
e509452727 sync: convert RWMutex.{readerCount,readerWait} to atomic type
Change-Id: I7fd9c0636cd00891f5cdf36c0f68f897772042f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/429767
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-09-09 18:28:35 +00:00
Cuong Manh Le
9dd9174fa5 sync/atomic: reduce inlining cost for atomic types methods
The "&x.v" cost us 2 inline cost budget, causing extra inline cost for
the caller. By taking the fact that "v" is laid out in memory as the
first field of all atomic types, we can accessing it without addressing.

Discovering why attempting to convert sync.RWMutex.readerCount to atomic
type. RWMutex.RUnlock have the inline cost 75, with extra 7 inline cost
from Int32.Add causing it not inlinable anymore.

With this change, Int32.Add only has 5 inline cost budget, RWMutex can
use it while still be inlinable.

Change-Id: Iabe1d1bf53389b0b8b5f56b4611231b732fd9df5
Reviewed-on: https://go-review.googlesource.com/c/go/+/429766
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Cuong Manh Le <cuong.manhle.vn@gmail.com>
2022-09-09 18:21:40 +00:00
Tobias Klauser
e2f602003b internal/poll, syscall: convert writev to direct libc call on openbsd (except mips64)
Add and use a writev libc wrapper instead of using syscall(2).

Updates golang/go#36435

Change-Id: I3c67665388ac276d9ef36868e368e91efb92800e
Reviewed-on: https://go-review.googlesource.com/c/go/+/428776
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Joel Sing <joel@sing.id.au>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-09-09 16:24:04 +00:00
Tobias Klauser
600db8a514 runtime/race: also unmap memory if TestNonGoMemory fails
Change-Id: I7ea150e4896fc9b2e3a6dbdd9a1c2b651e74b844
Reviewed-on: https://go-review.googlesource.com/c/go/+/428778
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-09 15:36:26 +00:00
cui fliter
861885841d go/ast: use strings.Builder
Change-Id: I9c4c3ada3a8f5d8d198cc42a4afc06972ee00c61
GitHub-Last-Rev: 4ed80119e3
GitHub-Pull-Request: golang/go#54916
Reviewed-on: https://go-review.googlesource.com/c/go/+/428921
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-09 15:35:30 +00:00
Andy Pan
4f3246c6e9 internal/poll: drop redundant ENOSYS in CopyFileRange
Update CL 425881 and CL 428396

I browsed the source code related to copy_file_range in the kernel and found that the latest kernel may still return EXDEV errors in copy_file_range(2) due to certain cases, for details see: https://elixir.bootlin.com/linux/v5.19.7/source/fs/read_write.c#L1559, https://elixir.bootlin.com/linux/v5.19.7/source/fs/read_write.c#L1479, and
https://elixir.bootlin.com/linux/v5.19.7/source/fs/read_write.c#L1439.

Therefore, the EXDEV still needs to be kept, but the ENOSYS error can be safely removed.

Change-Id: I47026b8dd33f7ffc4de1306af6b67c7b4d2062d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/428555
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Andy Pan <panjf2000@gmail.com>
2022-09-09 15:35:09 +00:00
Andy Pan
86477e507f os: add a test case of copying a file itself via io.Copy
Change-Id: Ib9746cb4f27625cb22620271b280d2da242b2fba
Reviewed-on: https://go-review.googlesource.com/c/go/+/428437
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Andy Pan <panjf2000@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
2022-09-09 15:34:46 +00:00
Kir Kolyshkin
bca17d16ca syscall: add CgroupFD support for ForkExec on Linux
Implement CLONE_INTO_CGROUP feature, allowing to put a child in a
specified cgroup in a clean and simple way. Note that the feature only
works for cgroup v2, and requires Linux kernel 5.7 or newer.

Using the feature requires a new syscall, clone3. Currently this is the
only reason to use clone3, but the code is structured in a way so that
other cases may be easily added in the future.

Add a test case.

While at it, try to simplify the syscall calling code in
forkAndExecInChild1, which became complicated over time because:

1. It was using either rawVforkSyscall or RawSyscall6 depending on
   whether CLONE_NEWUSER was set.

2. On Linux/s390, the first two arguments to clone(2) system call are
   swapped (which deserved a mention in Linux ABI hall of shame). It
   was worked around in rawVforkSyscall on s390, but had to be
   implemented via a switch/case when using RawSyscall6, making the code
   less clear.

Let's

 - modify rawVforkSyscall to have two arguments (which is also required
   for clone3);

 - remove the arguments workaround from s390 asm, instead implementing
   arguments swap in the caller (which still looks ugly but at least
   it's done once and is clearly documented now);

 - use rawVforkSyscall for all cases (since it is essentially similar to
   RawSyscall6, except for having less parameters, not returning r2, and
   saving/restoring the return address before/after syscall on 386 and
   amd64).

Updates #51246.

Change-Id: Ifcd418ebead9257177338ffbcccd0bdecb94474e
Reviewed-on: https://go-review.googlesource.com/c/go/+/417695
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Run-TryBot: Kirill Kolyshkin <kolyshkin@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-09-09 15:34:16 +00:00
Tobias Klauser
f53b2111e4 syscall: use unsafe.Slice instead of unsafeheader package
Change-Id: I9de5aafb36d05bdc90bbdba516367eb2b200a7e0
Reviewed-on: https://go-review.googlesource.com/c/go/+/428777
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
2022-09-09 15:30:06 +00:00
Abirdcfly
1b196988d4 cmd/go/internal/modload: use atomic.Pointer for Requirements.graph
Change-Id: Ie543e1b1df667cfaf3aafa4be727881461ee8b7d
GitHub-Last-Rev: ed993dbe24
GitHub-Pull-Request: golang/go#54888
Reviewed-on: https://go-review.googlesource.com/c/go/+/428716
Auto-Submit: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
2022-09-09 15:30:04 +00:00
Daniel Martí
9a5574afe6 go/printer: reduce allocations to improve performance
First, we know that Go source files almost always weigh at least a few
kilobytes, so we can kickstart the output buffer to be a reasonable size
and reduce the initial number of incremental allocations and copies when
appending bytes or strings to output.

Second, in nodeSize we use a nested printer, but we don't actually need
its printed bytes - we only need to know how many bytes it prints.
For that reason, use a throwaway buffer: the part of our output buffer
between length and capacity, as we haven't used it yet.

Third, use a sync.Pool to reuse allocated printers.
The current API doesn't allow reusing printers,
and some programs like gofmt will print many files in sequence.

Those changes combined result in a modest reduction in allocations and
CPU usage. The benchmark uses testdata/parser.go, which has just over
two thousand lines of code, which is pretty standard size-wise.

We also split the Print benchmark to cover both a medium-sized ast.File
as well as a pretty small ast.Decl node. The latter is a somewhat common
scenario in gopls, which has code actions which alter small bits of the
AST and print them back out to rewrite only a few lines in a file.

	name          old time/op    new time/op     delta
	PrintFile-16    5.43ms ± 1%     4.85ms ± 3%  -10.68%  (p=0.000 n=9+10)
	PrintDecl-16    19.1µs ± 0%     18.5µs ± 1%   -3.04%  (p=0.000 n=10+10)

	name          old speed      new speed       delta
	PrintFile-16  9.56MB/s ± 1%  10.69MB/s ± 3%  +11.81%  (p=0.000 n=8+10)
	PrintDecl-16  1.67MB/s ± 0%   1.73MB/s ± 1%   +3.05%  (p=0.000 n=10+10)

	name          old alloc/op   new alloc/op    delta
	PrintFile-16     332kB ± 0%      107kB ± 2%  -67.87%  (p=0.000 n=10+10)
	PrintDecl-16    3.92kB ± 0%     3.28kB ± 0%  -16.38%  (p=0.000 n=10+10)

	name          old allocs/op  new allocs/op   delta
	PrintFile-16     3.45k ± 0%      2.42k ± 0%  -29.90%  (p=0.000 n=10+10)
	PrintDecl-16      56.0 ± 0%       46.0 ± 0%  -17.86%  (p=0.000 n=10+10)

Change-Id: I475a3babca77532b2d51888f49710f74763d81d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/424924
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
2022-09-09 15:10:10 +00:00
Tobias Klauser
218294f11e internal/syscall/windows: use unsafe.Slice instead of unsafeheader package
Follow CL 428777.

Change-Id: I5ce49322e92c5d6539bb08248e3366187c30dcd8
Reviewed-on: https://go-review.googlesource.com/c/go/+/428780
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
2022-09-09 13:00:05 +00:00
hopehook
41089704dd all: transfer reflect.{SliceHeader, StringHeader} to unsafeheader.{Slice, String}
After we deprecated reflect.{SliceHeader, StringHeader}, it is recommended
to use unsafe.{Slice, String} to replace its work. However, the compiler
and linker cannot be migrated for the time being.

As a temporary strategy, using the "internal/unsafeheader" package like
other code is the most suitable choice at present.

For #53003.

Change-Id: I69d0ef72e2d95caabd0706bbb247a719d225c758
Reviewed-on: https://go-review.googlesource.com/c/go/+/429755
Auto-Submit: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: hopehook <hopehook@golangcn.org>
2022-09-09 01:59:25 +00:00