]> Cypherpunks repositories - gostls13.git/commit
time: optimize Parse for RFC3339 and RFC3339Nano
authorJoe Tsai <joetsai@digital-static.net>
Mon, 22 Aug 2022 18:29:03 +0000 (11:29 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 13 Sep 2022 17:35:58 +0000 (17:35 +0000)
commitf7396aaea0297a2e95b502a4075b0aed6efda89f
tree5907bc2902754bb68add5b46ae1be9098bf41bff
parent7ffbcd19876b9fbf117b09475411b8de9fa2c9dd
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>
src/time/export_test.go
src/time/format.go
src/time/format_test.go
src/time/time_test.go