Skip to content

time: improve performance of calendar algorithms and clarify its spec… #64600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

normandesjr
Copy link

@normandesjr normandesjr commented Dec 7, 2023

This implementation improves the performance of Go's time package using the recent algorithms developed by Neri and Schneider [1]. Their algorithms are faster than alternatives, my benchmarks confirm performance improvements in Go as well.

To achieve better performance we should change the supported range of dates: instead of supporting years taking any int value, they should be restricted to a much smaller range which still spans tens of thousands of years.

[1] Neri, C, Schneider, L. Euclidean affine functions and their application to calendar algorithms. Softw Pract Exper. 2023; 53(4): 937–970. doi:10.1002/spe.3172 https://onlinelibrary.wiley.com/doi/full/10.1002/spe.3172

For: #63844

…ification

This implementation improves the performance of Go's time package using the recent algorithms developed by Neri and Schneider [1]. Their algorithms are faster than alternatives, my benchmarks confirm performance improvements in Go as well.

```
goos: linux
goarch: amd64
pkg: time
cpu: Intel(R) Xeon(R) CPU E5-2680 v2 @ 2.80GHz
                       | /tmp/master.txt |   /tmp/nerishcneider.txt
                       |     sec/op      |   sec/op    vs base
Now-8                        69.38n ± 0%   69.33n ± 0%  -0.07% (p=0.001 n=20)
NowUnixNano-8                70.35n ± 0%   70.08n ± 0%  -0.38% (p=0.000 n=20)
NowUnixMilli-8               71.47n ± 0%   71.26n ± 0%  -0.30% (p=0.000 n=20)
NowUnixMicro-8               71.32n ± 0%   71.21n ± 0%  -0.15% (p=0.000 n=20)
Format-8                     441.9n ± 0%   433.8n ± 0%  -1.83% (p=0.000 n=20)
FormatRFC3339-8              293.9n ± 0%   283.4n ± 0%  -3.57% (p=0.000 n=20)
FormatRFC3339Nano-8          297.5n ± 0%   286.9n ± 0%  -3.55% (p=0.000 n=20)
FormatNow-8                  242.4n ± 0%   239.7n ± 0%  -1.11% (p=0.000 n=20)
MarshalJSON-8                144.0n ± 0%   136.2n ± 0%  -5.42% (p=0.000 n=20)
MarshalText-8                142.0n ± 0%   136.2n ± 0%  -4.02% (p=0.000 n=20)
Parse-8                      241.2n ± 0%   240.9n ± 0%  -0.12% (p=0.002 n=20)
ParseRFC3339UTC-8            78.52n ± 0%   73.12n ± 0%  -6.87% (p=0.000 n=20)
ParseRFC3339UTCBytes-8       86.60n ± 0%   81.05n ± 0%  -6.42% (p=0.000 n=20)
ParseRFC3339TZ-8             291.5n ± 0%   283.1n ± 0%  -2.90% (p=0.000 n=20)
ParseRFC3339TZBytes-8        343.2n ± 0%   333.2n ± 0%  -2.93% (p=0.000 n=20)
ParseDuration-8              125.6n ± 0%   125.8n ± 0%  +0.16% (p=0.002 n=20)
Hour-8                       6.458n ± 0%   6.457n ± 0%       ~ (p=0.130 n=20)
Second-8                     6.460n ± 0%   6.456n ± 0%  -0.05% (p=0.002 n=20)
Year-8                       18.68n ± 0%   14.10n ± 0% -24.52% (p=0.000 n=20)
Day-8                        24.01n ± 0%   17.14n ± 0% -28.61% (p=0.000 n=20)
ISOWeek-8                    27.55n ± 0%   24.46n ± 0% -11.22% (p=0.000 n=20)
GoString-8                   157.9n ± 0%   152.9n ± 0%  -3.13% (p=0.000 n=20)
UnmarshalText-8              290.1n ± 0%   283.4n ± 0%  -2.31% (p=0.000 n=20)
Geomean                      93.84n ± 0%   89.08n ± 0%  -5.07%
```

To achieve better performance we should change the supported range of dates: instead of supporting years taking any int value, they should be restricted to a much smaller range which still spans tens of thousands of years.

[1] Neri, C, Schneider, L. Euclidean affine functions and their application to calendar algorithms. Softw Pract Exper. 2023; 53(4): 937–970. doi:10.1002/spe.3172
https://onlinelibrary.wiley.com/doi/full/10.1002/spe.3172

For: golang#63844
@gopherbot
Copy link
Contributor

This PR (HEAD: 6d98312) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/548155.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/548155.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Gopher Robot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.


Please don’t reply on this GitHub thread. Visit golang.org/cl/548155.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from [email protected]:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/548155.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Vadim Vygonets:

Patch Set 1:

(3 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/548155.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

Message from Alexander Yastrebov:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/548155.
After addressing review feedback, remember to publish your drafts!

@gopherbot
Copy link
Contributor

This PR (HEAD: 59ed4dd) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/548155.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants