]> Cypherpunks repositories - gostls13.git/commit
time: improve ParseDuration performance for invalid input
authorapocelipes <seve3r@outlook.com>
Fri, 19 Sep 2025 10:34:09 +0000 (10:34 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 19 Sep 2025 15:33:55 +0000 (08:33 -0700)
commitee7bf06cb306ea9234fbc1501f3e0f3903ada427
treea61b427477cf1cd02c51e9999bbda69521d23e6a
parentf9e61a9a32c8cbfd810ac9fec135b5c0911b8d69
time: improve ParseDuration performance for invalid input

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>
src/time/format.go
src/time/time_test.go