aboutsummaryrefslogtreecommitdiff
path: root/src/time
AgeCommit message (Collapse)Author
2026-02-03all: prealloc slice with possible minimum capabilitiesShulhan
2025-12-23time: skip test that will fail with GO111MODULE=offKevin Burke
The test is designed to ensure that behavior introduced in Go 1.23 to garbage collect async timed channels is working correctly. If GO111MODULE=off is set (or GODEBUG=asynctimerchan=1) Go reverts to the Go 1.20 behavior of not garbage collecting these channels, which fails the test. Instead of running a test in conditions where we know it will fail, just skip the test. A more comprehensive test does not make sense right now because this code may go away soon. Fixes #76948. Change-Id: Ib186abd2ea583a06b5c246bfd6df932522cf7f1e Reviewed-on: https://go-review.googlesource.com/c/go/+/732100 Reviewed-by: Nicholas Husin <husin@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-29internal/itoa, internal/runtime/strconv: deleteRuss Cox
Replaced by internal/strconv. Change-Id: I0656a9ad5075e60339e963fbae7d194d2f3e16be Reviewed-on: https://go-review.googlesource.com/c/go/+/716001 Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-10-27time: rewrite IsZero method to use wall and ext fieldsbaycore
Using wall and ext fields will be more efficient. Fixes #76001 Change-Id: If2b9f597562e0d0d3f8ab300556fa559926480a0 GitHub-Last-Rev: 4a91948413079047cb6c382ed29844f456f3064d GitHub-Pull-Request: golang/go#76006 Reviewed-on: https://go-review.googlesource.com/c/go/+/713720 Reviewed-by: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: David Chase <drchase@google.com>
2025-10-17all: remove unnecessary loop variable copies in testsTobias Klauser
Copying the loop variable is no longer necessary since Go 1.22. Change-Id: Iebb21dac44a20ec200567f1d786f105a4ee4999d Reviewed-on: https://go-review.googlesource.com/c/go/+/711640 Reviewed-by: Florian Lehner <lehner.florian86@gmail.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-09-19time: improve ParseDuration performance for invalid inputapocelipes
Add "parseDurationError" to reduce memory allocation in the error path of "ParseDuration" and delay the generation of error messages. This improves the performance when dealing with invalid input. The format of the error message remains unchanged. Benchmarks: │ old │ new │ │ sec/op │ sec/op vs base │ ParseDurationError-10 132.10n ± 4% 45.93n ± 2% -65.23% (p=0.000 n=10) │ old │ new │ │ B/op │ B/op vs base │ ParseDurationError-10 192.00 ± 0% 64.00 ± 0% -66.67% (p=0.000 n=10) │ old │ new │ │ allocs/op │ allocs/op vs base │ ParseDurationError-10 6.000 ± 0% 2.000 ± 0% -66.67% (p=0.000 n=10) Fixes #75521 Change-Id: I0dc9f28c9601b6be07b70d0a98613757d76e2c97 GitHub-Last-Rev: 737273936ad0cafd710fa58d99333416e71e657e GitHub-Pull-Request: golang/go#75531 Reviewed-on: https://go-review.googlesource.com/c/go/+/705195 Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Alan Donovan <adonovan@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-08-28time: skip TestLongAdjustTimers in short mode on single CPU systemsJoel Sing
The OpenBSD armv7 port does not support SMP - on this platform the TestLongAdjustTimers test passes in ~46 seconds on the openbsd/arm builder when there is no other CPU contention, however it will almost always fail when there is any other load. Change-Id: Idf1c47b40376c749886843cdae11289c0984f714 Reviewed-on: https://go-review.googlesource.com/c/go/+/698556 TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Michael Knyszek <mknyszek@google.com> Commit-Queue: Cherry Mui <cherryyz@google.com> Run-TryBot: Joel Sing <joel@sing.id.au> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com>
2025-08-07time: skip TestLongAdjustTimers on plan9 (too slow)Richard Miller
The TestLongAdjustTimers test has been consistently timing out after 60 seconds on plan9-arm. Skip the test for plan9, as it is already skipped for being too slow on android and ios. Fixes #74921 Change-Id: Icc32e902cecd2e98971a898373fe8346b179437d Reviewed-on: https://go-review.googlesource.com/c/go/+/693955 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Mark Freeman <markfreeman@google.com>
2025-07-28all: omit unnecessary type conversionsJes Cok
Found by github.com/mdempsky/unconvert Change-Id: Ib78cceb718146509d96dbb6da87b27dbaeba1306 GitHub-Last-Rev: dedf354811701ce8920c305b6f7aa78914a4171c GitHub-Pull-Request: golang/go#74771 Reviewed-on: https://go-review.googlesource.com/c/go/+/690735 Reviewed-by: Mark Freeman <mark@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Keith Randall <khr@google.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
2025-07-24time: remove redundant uint32 conversion in splitcxbdasheng
cd is a uint32 converted again. Change-Id: Ia41e247e0644c17cd9e0593d79457db77512fc3e GitHub-Last-Rev: 1ba8596e2761be75cc35f79e8245a96d6bb81096 GitHub-Pull-Request: golang/go#74679 Reviewed-on: https://go-review.googlesource.com/c/go/+/689055 Auto-Submit: Jorropo <jorropo.pgm@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Keith Randall <khr@google.com> Reviewed-by: Jorropo <jorropo.pgm@gmail.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-04-18encoding/json: add json/v2 with GOEXPERIMENT=jsonv2 guardDamien Neil
This imports the proposed new v2 JSON API implemented in github.com/go-json-experiment/json as of commit d3c622f1b874954c355e60c8e6b6baa5f60d2fed. When GOEXPERIMENT=jsonv2 is set, the encoding/json/v2 and encoding/jsontext packages are visible, the encoding/json package is implemented in terms of encoding/json/v2, and the encoding/json package include various additional APIs. (See #71497 for details.) When GOEXPERIMENT=jsonv2 is not set, the new API is not present and the encoding/json package is unchanged. The experimental API is not bound by the Go compatibility promise and is expected to evolve as updates are made to the json/v2 proposal. The contents of encoding/json/internal/jsontest/testdata are compressed with zstd v1.5.7 with the -19 option. Fixes #71845 For #71497 Change-Id: Ib8c94e5f0586b6aaa22833190b41cf6ef59f4f01 Reviewed-on: https://go-review.googlesource.com/c/go/+/665796 Auto-Submit: Damien Neil <dneil@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2025-04-11all: use built-in min, max functionsMarcel Meyer
Change-Id: Ie76ebb556d635068342747f3f91dd7dc423df531 GitHub-Last-Rev: aea61fb3a054e6bd24f4684f90fb353d5682cd0b GitHub-Pull-Request: golang/go#73340 Reviewed-on: https://go-review.googlesource.com/c/go/+/664677 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com>
2025-04-11time: remove redundant int conversion in tzruleTime1911860538
daysBefore returns int. Change-Id: Ib30c9ea76b46178a4fc35e8198aaab913329ceba GitHub-Last-Rev: 2999e99dad8bfd075fdc942def1de2593d920c79 GitHub-Pull-Request: golang/go#73182 Reviewed-on: https://go-review.googlesource.com/c/go/+/663275 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Carlos Amedee <carlos@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Sean Liao <sean@liao.dev>
2025-04-08time: add examples for AppendBinary and AppendTextcuishuang
Change-Id: I61529b5162f8a77d3bbffcbbac98c834a7626e3a Reviewed-on: https://go-review.googlesource.com/c/go/+/661935 Reviewed-by: Sean Liao <sean@liao.dev> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Sean Liao <sean@liao.dev> Reviewed-by: Carlos Amedee <carlos@golang.org>
2025-03-18runtime, time: don't use monotonic clock inside synctest bubblesDamien Neil
Don't include a monotonic time in time.Times created inside a bubble, to avoid the confusion of different Times using different monotonic clock epochs. For #67434 goos: darwin goarch: arm64 pkg: time cpu: Apple M1 Pro │ /tmp/bench.0 │ /tmp/bench.1 │ │ sec/op │ sec/op vs base │ Since-10 18.42n ± 2% 18.68n ± 1% ~ (p=0.101 n=10) Until-10 18.28n ± 2% 18.46n ± 2% +0.98% (p=0.009 n=10) geomean 18.35n 18.57n +1.20% Change-Id: Iaf1b80d0a4df52139c5b80d4bde4410ef8a49f2f Reviewed-on: https://go-review.googlesource.com/c/go/+/657415 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Michael Pratt <mpratt@google.com>
2025-03-14time: optimize quote using byte(c) for ASCII1911860538
Since c < runeSelf && c >= ' ' (i.e., 32 <= c < 128), using buf = append(buf, byte(c)) instead of buf = append(buf, string(c)...) is a better choice, as it provides better performance. Change-Id: Ic0ab25c71634a1814267f4d85be2ebd8a3d44676 GitHub-Last-Rev: 5445b547712bbfc77a5c17d76194291c22eb4a05 GitHub-Pull-Request: golang/go#72820 Reviewed-on: https://go-review.googlesource.com/c/go/+/657055 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-11-19internal/synctest: new package for testing concurrent codeDamien Neil
Add an internal (for now) implementation of testing/synctest. The synctest.Run function executes a tree of goroutines in an isolated environment using a fake clock. The synctest.Wait function allows a test to wait for all other goroutines within the test to reach a blocking point. For #67434 For #69687 Change-Id: Icb39e54c54cece96517e58ef9cfb18bf68506cfc Reviewed-on: https://go-review.googlesource.com/c/go/+/591997 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-11-12time: regenerate zoneinfo_abbrs_windows.goIan Lance Taylor
For #58113 Change-Id: I5833a898991d8ac1f564863c1c63eb3e2e86f7c7 Reviewed-on: https://go-review.googlesource.com/c/go/+/626756 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Commit-Queue: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-11-05time: add examples for Since, Until, Abs and fix some commentscuishuang
Change-Id: I33b61629dfabffa15065a14fccdb418bab11350d Reviewed-on: https://go-review.googlesource.com/c/go/+/623915 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: David Chase <drchase@google.com>
2024-11-05time: accept "+01" in TestLoadFixed on OpenBSDDmitri Shuralyov
This stops the test from failing with a known failure mode, and creates time to look into what the next steps should be, if any. For #69840. Change-Id: I060903d256ed65c5dfcd70ae76eb361cab63186f Cq-Include-Trybots: luci.golang.try:gotip-openbsd-amd64 Reviewed-on: https://go-review.googlesource.com/c/go/+/625197 Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Eric Grosse <grosse@gmail.com>
2024-10-21runtime,time: use atomic.Int32 for isSendingMichael Anthony Knyszek
This change switches isSending to be an atomic.Int32 instead of an atomic.Uint8. The Int32 version is managed as a counter, which is something that we couldn't do with Uint8 without adding a new intrinsic which may not be available on all architectures. That is, instead of only being able to support 8 concurrent timer firings on the same timer because we only have 8 independent bits to set for each concurrent timer firing, we can now have 2^31-1 concurrent timer firings before running into any issues. Like the fact that each bit-set was matched with a clear, here we match increments with decrements to indicate that we're in the "sending on a channel" critical section in the timer code, so we can report the correct result back on Stop or Reset. We choose an Int32 instead of a Uint32 because it's easier to check for obviously bad values (negative values are always bad) and 2^31-1 concurrent timer firings should be enough for anyone. Previously, we avoided anything bigger than a Uint8 because we could pack it into some padding in the runtime.timer struct. But it turns out that the type that actually matters, runtime.timeTimer, is exactly 96 bytes in size. This means its in the next size class up in the 112 byte size class because of an allocation header. We thus have some free space to work with. This change increases the size of this struct from 96 bytes to 104 bytes. (I'm not sure if runtime.timer is often allocated directly, but if it is, we get lucky in the same way too. It's exactly 80 bytes in size, which means its in the 96-byte size class, leaving us with some space to work with.) Fixes #69969. Related to #69880 and #69312. Change-Id: I9fd59cb6a69365c62971d1f225490a65c58f3e77 Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest Reviewed-on: https://go-review.googlesource.com/c/go/+/621616 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-17time: correct time.AppendText's error messageapocelipes
"time.AppendText" returns error messages that start with the prefix "time.MarshalText: " which seems confusion. Now correct the message prefix to "time.AppendText: " and add a test to prevent regression. Change-Id: I5742c9c3ed802eb79c65d459910deae4f3652ffd GitHub-Last-Rev: ce965595c1dafab4a3db3d3f9f9edc9e43c5dea2 GitHub-Pull-Request: golang/go#69914 Reviewed-on: https://go-review.googlesource.com/c/go/+/620597 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-10-14timer: fix Stop link in Timer.Reset doc commentRobert Pająk
Change-Id: I0fccb18b2d5d3f7c86f026c988f90734546f7be0 GitHub-Last-Rev: a72cfe970e74dd3a9fffec9604ae58126514542c GitHub-Pull-Request: golang/go#69856 Reviewed-on: https://go-review.googlesource.com/c/go/+/619056 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
2024-10-14runtime: don't frob isSending for tickersIan Lance Taylor
The Ticker Stop and Reset methods don't report a value, so we don't need to track whether they are interrupting a send. This includes a test that used to fail about 2% of the time on my laptop when run under x/tools/cmd/stress. Change-Id: Ic6d14b344594149dd3c24b37bbe4e42e83f9a9ad Reviewed-on: https://go-review.googlesource.com/c/go/+/620136 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Michael Knyszek <mknyszek@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2024-09-26runtime: if stop/reset races with running timer, return correct resultIan Lance Taylor
The timer code is careful to ensure that if stop/reset is called while a timer is being run, we cancel the run. However, the code failed to ensure that in that case stop/reset returned true, meaning that the timer had been stopped. In the racing case stop/reset could see that t.when had been set to zero, and return false, even though the timer had not and never would fire. Fix this by tracking whether a timer run is in progress, and using that to reliably detect that the run was cancelled, meaning that stop/reset should return true. Fixes #69312 Change-Id: I78e870063eb96650638f12c056e32c931417c84a Reviewed-on: https://go-review.googlesource.com/c/go/+/611496 Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2024-09-10time: don't check non-nil err twice in parseTobias Klauser
Change-Id: I40a1b49035321b05032eacf4525a62b8c562e0d0 Reviewed-on: https://go-review.googlesource.com/c/go/+/612195 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Tim King <taking@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-09-09all: remove unnecessary symbols and add missing symbolscuishuang
Change-Id: I535a7aaaf3f9e8a9c0e0c04f8f745ad7445a32f7 Reviewed-on: https://go-review.googlesource.com/c/go/+/611678 Run-TryBot: shuang cui <imcusg@gmail.com> 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> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
2024-09-03all: omit unnecessary 0 in slice expressionnlwkobe30
All changes are related to the code, except for the comments in src/regexp/syntax/parse.go and src/slices/slices.go. Change-Id: I73c5d3c54099749b62210aa7f3182c5eb84bb6a6 GitHub-Last-Rev: 794aa9b0539811d00e1cd42be1e8d9fe9afe0281 GitHub-Pull-Request: golang/go#69170 Reviewed-on: https://go-review.googlesource.com/c/go/+/609678 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-08-20time: implement the encoding.(Binary|Text)Appender for Timeapocelipes
"Time.Marshal(Binary|Text)" could also gain some performance improvements. Here is the benchmark highlight: │ old │ new │ │ sec/op │ sec/op vs base │ MarshalText-8 104.00n ± 3% 67.27n ± 2% -35.32% (p=0.000 n=10) MarshalBinary-8 31.77n ± 2% 12.13n ± 1% -61.82% (p=0.000 n=10) geomean 57.48n 28.57n -50.30% │ old │ new │ │ B/op │ B/op vs base │ MarshalText-8 48.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10) MarshalBinary-8 16.00 ± 0% 0.00 ± 0% -100.00% (p=0.000 n=10) │ old │ new │ │ allocs/op │ allocs/op vs base │ MarshalText-8 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) MarshalBinary-8 1.000 ± 0% 0.000 ± 0% -100.00% (p=0.000 n=10) For #62384 Change-Id: I320421878a341abf8d668fd57b27292cdfa61330 GitHub-Last-Rev: e04f8df9c277481f5678208d3f1f59643bf5e429 GitHub-Pull-Request: golang/go#68942 Reviewed-on: https://go-review.googlesource.com/c/go/+/606655 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-08-20time: fix godoc links; remove redundant Sub mentionOleksandr Redko
The Time.Sub function is mentioned in the previous sentence. Change-Id: Ic79958cea4d1f9f9014f6dafd8e749c204db4f50 Reviewed-on: https://go-review.googlesource.com/c/go/+/606575 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-08-03time: restore support for large negative days in DateIan Lance Taylor
CL 586257 converted days to uint32 which is usually fine but fails for negative days close to cycle boundaries. Fixes #68718 Change-Id: I8dc5b8fe0c7c1921beb204da1913b9a1ab39280d Reviewed-on: https://go-review.googlesource.com/c/go/+/602815 Reviewed-by: Rob Pike <r@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-08-02time: fix some typos in CL 512355Jes Cok
Change-Id: Id0fb180a2d7910cdff7f4ab7154d9ceeb2f1cb71 GitHub-Last-Rev: 03658dd9747684f69ea238a8d1d7f7d15446099e GitHub-Pull-Request: golang/go#68709 Reviewed-on: https://go-review.googlesource.com/c/go/+/602675 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com>
2024-07-31time: optimize time <-> date conversionsRuss Cox
Optimize the time -> date and date -> time conversions using the methods outlined in: Cassio Neri and Lorenz Schneider, “Euclidean affine functions and their application to calendar algorithms,” SP&E 2023. https://doi.org/10.1002/spe.3172 I took the opportunity to introduce some types to make the code significantly clearer and optimize a few other parts I noticed along the way. The result is noticeably faster across the board. Probably this doesn't matter much in real programs, but all the other languages are picking this up, and it is less code than what we had before. Proposal #63844 suggested adopting this algorithm and simultaneously restricting the range of valid years supported by the package from its current ±292277022399 (plenty for anyone) to a mere ±32767. This CL does NOT make any such restriction. The range of valid years is almost exactly what it was before. (It is the same size but shifted 10 months earlier, which no one will ever care about.) This CL removes any real need to consider the proposal, since it would be a breaking change for truly insignificant benefit. Thanks to Normandes Junior and Cassio Neri for CL 548155 and for discussion on #63844, which prompted me to write this CL. This CL is all new code and does not include code from CL 548155 except as noted in the isLeap function implementation. For #63844. goos: linux goarch: amd64 pkg: time cpu: AMD Ryzen 9 7950X 16-Core Processor │ timeold.txt │ timenew.txt │ │ sec/op │ sec/op vs base │ Format-32 156.5n ± 1% 148.1n ± 1% -5.37% (n=125) FormatRFC3339-32 118.5n ± 1% 112.1n ± 1% -5.40% (n=125) FormatRFC3339Nano-32 119.2n ± 1% 113.0n ± 1% -5.20% (n=125) FormatNow-32 96.88n ± 2% 97.22n ± 1% ~ (p=0.173 n=125) MarshalJSON-32 79.77n ± 1% 75.82n ± 1% -4.95% (n=125) MarshalText-32 79.25n ± 1% 76.18n ± 1% -3.87% (p=0.000 n=125) Parse-32 79.80n ± 1% 78.28n ± 1% -1.90% (p=0.000 n=125) ParseRFC3339UTC-32 29.10n ± 1% 28.90n ± 0% ~ (p=0.094 n=125) ParseRFC3339UTCBytes-32 30.72n ± 1% 30.88n ± 1% ~ (p=0.894 n=125) ParseRFC3339TZ-32 92.29n ± 0% 90.27n ± 1% -2.19% (p=0.000 n=125) ParseRFC3339TZBytes-32 133.4n ± 1% 132.0n ± 1% ~ (p=0.004 n=125) ParseDuration-32 41.11n ± 3% 44.08n ± 2% ~ (p=0.088 n=125) Hour-32 2.834n ± 0% 2.829n ± 1% ~ (p=0.891 n=125) Second-32 2.811n ± 1% 2.828n ± 1% ~ (p=0.208 n=125) Date-32 9.228n ± 1% 5.788n ± 0% -37.28% (n=125) Year-32 6.404n ± 1% 4.673n ± 1% -27.03% (n=125) YearDay-32 6.399n ± 1% 5.802n ± 0% -9.33% (n=125) Month-32 9.108n ± 1% 4.700n ± 1% -48.40% (n=125) Day-32 9.106n ± 1% 4.686n ± 1% -48.54% (n=125) ISOWeek-32 10.060n ± 0% 7.998n ± 1% -20.50% (n=125) GoString-32 84.59n ± 1% 83.82n ± 1% ~ (p=0.027 n=125) DateFunc-32 6.993n ± 0% 6.144n ± 1% -12.14% (n=125) UnmarshalText-32 94.78n ± 2% 89.49n ± 1% -5.58% (n=125) geomean 29.60n 26.13n -11.70% goos: darwin goarch: arm64 pkg: time cpu: Apple M3 Pro │ timeold-m3.txt │ timenew-m3.txt │ │ sec/op │ sec/op vs base │ Format-12 152.6n ± 0% 147.4n ± 0% -3.41% (n=125) FormatRFC3339-12 101.50n ± 0% 92.02n ± 0% -9.34% (n=125) FormatRFC3339Nano-12 101.30n ± 0% 92.68n ± 0% -8.51% (n=125) FormatNow-12 93.50n ± 0% 94.65n ± 0% +1.23% (p=0.000 n=125) MarshalJSON-12 50.06n ± 0% 48.25n ± 0% -3.62% (n=125) MarshalText-12 49.70n ± 0% 47.51n ± 0% -4.41% (n=125) Parse-12 97.91n ± 0% 95.90n ± 0% -2.05% (n=125) ParseRFC3339UTC-12 36.45n ± 0% 35.78n ± 1% -1.84% (n=125) ParseRFC3339UTCBytes-12 38.11n ± 0% 37.42n ± 0% -1.81% (n=125) ParseRFC3339TZ-12 100.80n ± 1% 97.58n ± 0% -3.19% (n=125) ParseRFC3339TZBytes-12 111.8n ± 1% 107.4n ± 0% -3.94% (n=125) ParseDuration-12 52.70n ± 0% 52.84n ± 0% ~ (p=0.028 n=125) Hour-12 2.657n ± 0% 2.655n ± 0% ~ (p=0.018 n=125) Second-12 2.656n ± 0% 2.654n ± 0% ~ (p=0.084 n=125) Date-12 8.201n ± 0% 5.055n ± 0% -38.36% (n=125) Year-12 5.694n ± 0% 4.086n ± 0% -28.24% (n=125) YearDay-12 5.693n ± 0% 4.828n ± 0% -15.19% (n=125) Month-12 8.206n ± 0% 4.231n ± 0% -48.44% (n=125) Day-12 8.199n ± 0% 4.551n ± 0% -44.49% (n=125) ISOWeek-12 9.032n ± 0% 7.298n ± 0% -19.20% (n=125) GoString-12 62.78n ± 0% 60.61n ± 0% -3.46% (n=125) DateFunc-12 7.318n ± 0% 6.431n ± 0% -12.12% (n=125) UnmarshalText-12 99.66n ± 0% 95.64n ± 0% -4.03% (n=125) Change-Id: I089a072a731914702f8087018d00960e129f86b0 Reviewed-on: https://go-review.googlesource.com/c/go/+/586257 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-07-02time: fix time zone parsing when format includes time zone secondsDarin Krauss
The current implementation fails to parse a time string with a "Z" time zone using a time format that includes time zone seconds. This fix correctly parses the "Z" time zone for any Z-base time format that includes seconds (i.e. "Z070000" or "Z07:00:00"). Fixes #68263 Change-Id: Idf8fa06b5f96383f050c4ffbd2bc5804fd408650 Reviewed-on: https://go-review.googlesource.com/c/go/+/595897 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com>
2024-06-21time: provide non-default metric for asynctimerchanRuss Cox
The original implementation could not support a non-default metric, but now that it is set during package time, we can. Do that. Change-Id: If7929b0afa5b0142d299718d9bd811c5a8d1cf93 Reviewed-on: https://go-review.googlesource.com/c/go/+/589058 Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-06-11time: correct spelling, queing -> queuingJes Cok
Change-Id: I418953a766db22b134a9569161f06cf8682c1eef Reviewed-on: https://go-review.googlesource.com/c/go/+/591336 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-06-11time: add to format documentation about dangers of using RFC1123{,Z} for parsingDana Burkart
When using time.RFC1123Z to parse the date header value out of an email, an error is returned for dates that occur in the first 9 days of a month. This is because the format strings for RFC 1123 defined in the time package indicate that the day should be prefixed with a leading 0. Reading the spec, the line that talks about it seems to indicate that days can be either 1 or 2 digits: `date = 1*2DIGIT month 2*4DIGIT` So a date header with a day like `7` with no leading zero should be accepted. Fixes #67887 Change-Id: Ie7ee40d94da2c8c0417957e8b89f9987314949c8 GitHub-Last-Rev: 22a5a52fcb7ee25e5005bb9a014ef8a94d52fb32 GitHub-Pull-Request: golang/go#67888 Reviewed-on: https://go-review.googlesource.com/c/go/+/591335 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-06-03time: time/internal_test.go remove redundant type conversionhxzhouh
Change-Id: I5aaea4918f024a87146ba54a8d5307658d722fe9 Reviewed-on: https://go-review.googlesource.com/c/go/+/589635 Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: hui zhou <hxzhouh@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Knyszek <mknyszek@google.com>
2024-05-29all: document legacy //go:linkname for final round of modulesRuss Cox
Add linknames for most modules with ≥50 dependents. Add linknames for a few other modules that we know are important but are below 50. Remove linknames from badlinkname.go that do not merit inclusion (very small number of dependents). We can add them back later if the need arises. Fixes #67401. (For now.) Change-Id: I1e49fec0292265256044d64b1841d366c4106002 Reviewed-on: https://go-review.googlesource.com/c/go/+/587756 Auto-Submit: Russ Cox <rsc@golang.org> TryBot-Bypass: Russ Cox <rsc@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com>
2024-05-29all: document legacy //go:linkname for modules with ≥100 dependentsRuss Cox
For #67401. Change-Id: I015408a3f437c1733d97160ef2fb5da6d4efcc5c Reviewed-on: https://go-review.googlesource.com/c/go/+/587598 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Russ Cox <rsc@golang.org>
2024-05-23time: add a few more benchmarksRuss Cox
Preparation for upcoming optimizations. For #63844. Change-Id: I61803dd8b699e51c391614c99ebbd005df5261cc Reviewed-on: https://go-review.googlesource.com/c/go/+/586256 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-05-23all: document legacy //go:linkname for modules with ≥200 dependentsRuss Cox
Ignored these linknames which have not worked for a while: github.com/xtls/xray-core: context.newCancelCtx removed in CL 463999 (Feb 2023) github.com/u-root/u-root: funcPC removed in CL 513837 (Jul 2023) tinygo.org/x/drivers: net.useNetdev never existed For #67401. Change-Id: I9293f4ef197bb5552b431de8939fa94988a060ce Reviewed-on: https://go-review.googlesource.com/c/go/+/587576 Auto-Submit: Russ Cox <rsc@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-23all: change from sort functions to slices functions where feasibleIan Lance Taylor
Doing this because the slices functions are slightly faster and slightly easier to use. It also removes one dependency layer. This CL does not change packages that are used during bootstrap, as the bootstrap compiler does not have the required slices functions. It does not change the go/scanner package because the ErrorList Len, Swap, and Less methods are part of the Go 1 API. Change-Id: If52899be791c829198e11d2408727720b91ebe8a Reviewed-on: https://go-review.googlesource.com/c/go/+/587655 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com>
2024-05-23time: check for time zone offset overflowIan Lance Taylor
Fixes #67470 Change-Id: Idc5997859602ff6155aa9ae875b327fbcb53513d Reviewed-on: https://go-review.googlesource.com/c/go/+/586717 Reviewed-by: Alan Donovan <adonovan@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Commit-Queue: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-17all: add push linknames to allow legacy pull linknamesCherry Mui
CL 585358 adds restrictions to disallow pull-only linknames (currently off by default). Currently, there are quite some pull- only linknames in user code in the wild. In order not to break those, we add push linknames to allow them to be pulled. This CL includes linknames found in a large code corpus (thanks Matthew Dempsky and Michael Pratt for the analysis!), that are not currently linknamed. Updates #67401. Change-Id: I32f5fc0c7a6abbd7a11359a025cfa2bf458fe767 Reviewed-on: https://go-review.googlesource.com/c/go/+/586137 Reviewed-by: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-15cmd/link: disallow pull-only linknamesCherry Mui
As mentioned in CL 584598, linkname is a mechanism that, when abused, can break API integrity and even safety of Go programs. CL 584598 is a first step to restrict the use of linknames, by implementing a blocklist. This CL takes a step further, tightening up the restriction by allowing linkname references ("pull") only when the definition side explicitly opts into it, by having a linkname on the definition (possibly to itself). This way, it is at least clear on the definition side that the symbol, despite being unexported, is accessed outside of the package. Unexported symbols without linkname can now be actually private. This is similar to the symbol visibility rule used by gccgo for years (which defines unexported non-linknamed symbols as C static symbols). As there can be pull-only linknames in the wild that may be broken by this change, we currently only enforce this rule for symbols defined in the standard library. Push linknames are added in the standard library to allow things build. Linkname references to external (non-Go) symbols are still allowed, as their visibility is controlled by the C symbol visibility rules and enforced by the C (static or dynamic) linker. Assembly symbols are treated similar to linknamed symbols. This is controlled by -checklinkname linker flag, currently not enabled by default. A follow-up CL will enable it by default. Change-Id: I07344f5c7a02124dbbef0fbc8fec3b666a4b2b0e Reviewed-on: https://go-review.googlesource.com/c/go/+/585358 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Than McIntosh <thanm@google.com> Reviewed-by: Russ Cox <rsc@golang.org>
2024-05-14time: more flake removal in asynctimerchan testRuss Cox
Trying to write a test for the corner cases in the old async timer chan implementation may have been a mistake, especially since this isn't going to be the default timer chan implementation anymore. But let's try one more time to fix the test. I reproduced the remaining builder failures on my Mac laptop by overloading the CPU in one window and then running 48 instances of the flaky test in loops using 'stress' in another window. It turns out that, contrary to my understanding of async timers and therefore contrary to what the test expected, it is technically possible for t := time.NewTicker(1) t.Reset(1000*time.Hour) <-t.C <-t.C to observe two time values on t.C, as opposed to blocking forever. We always expect the first time value, since the ticker goes off immediately (after 1ns) and sends that value into the channel buffer. To get the second value, the ticker has to be in the process of going off (which it is doing constantly anyway), and the timer goroutine has to be about to call sendTime and then get rescheduled. Then t.Reset and the first <-t.C have to happen. Then the timer goroutine gets rescheduled and can run sendTime's non-blocking send on t.C, which finds an empty buffer and writes a value. This is unlikely, of course, but it definitely happens. This program always panics in just a second or two on my laptop: package main import ( "os" "time" ) func main() { os.Setenv("GODEBUG", "asynctimerchan=1") for { go func() { t := time.NewTicker(1) t.Reset(1000*time.Hour) <-t.C select { case <-t.C: panic("two receives") case <-time.After(1*time.Second): } }() } } Because I did not understand this nuance, the test did not expect it. This CL rewrites the test to expect that possibility. I can no longer make the test fail under 'stress' on my laptop. For #66322. Change-Id: I15c75d2c6f24197c43094da20d6ab55306a0a9f1 Reviewed-on: https://go-review.googlesource.com/c/go/+/585359 Reviewed-by: Cherry Mui <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Russ Cox <rsc@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2024-05-08time: more deflaking asynctimer testsRuss Cox
For #66322. Change-Id: I1d83c7a3cacd2ab012039d954270a7c87bbdf5ce Reviewed-on: https://go-review.googlesource.com/c/go/+/584195 Reviewed-by: Cherry Mui <cherryyz@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Russ Cox <rsc@golang.org>
2024-05-05time: use stringslite.Cloneqiulaidongfeng
Change-Id: I82f0e7c0c0c80a3cc0e4a732a59ae1debb37d8d9 GitHub-Last-Rev: c8a081f5b37e26058dd0278464950e81e045ab95 GitHub-Pull-Request: golang/go#67166 Reviewed-on: https://go-review.googlesource.com/c/go/+/583195 Commit-Queue: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com>
2024-04-29time: add notes about monotonic time pausedplasmatium
See #66870 Change-Id: I781265355a3dbd0d9538bc9dcafaa83b482ec3f8 GitHub-Last-Rev: 9d92f116b05db5568dd4d5834bace659eaf8cc49 GitHub-Pull-Request: golang/go#66922 Reviewed-on: https://go-review.googlesource.com/c/go/+/580515 Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>