Skip to content
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

Perf: Use computed offset passed in DateTime constructor #1576

Merged

Conversation

schleyfox
Copy link
Contributor

This is part of a series of PRs based on performance work we have done to
improve a use-case involving parsing/formatting hundreds of thousands of dates
where luxon was the bottleneck.

This includes the commit from #1574 to establish the benchmark

All calls to the datetime constructor that pass an offset (o), have just
computed that offset (quickDT, fromObject) except for clone(). Clone
passes an "old" option to determine whether previous offset can be
reused. If we have config.o, but config.old is not set, then we can use
o without computing it.

This saves an expensive call to zone.offset that duplicates work that
was done immediately prior.

Benchmark Comparison (name | before | after | after/before):

DateTime.fromObject with locale | 1,112,953 ±0.08% | 1,263,335 ±0.10% | 1.14x
DateTime.local with numbers | 844,898 ±0.15% | 943,140 ±0.13% | 1.12x
DateTime.local with numbers and zone | 50,913 ±0.18% | 66,671 ±0.14% | 1.31x
DateTime.fromFormat with zone | 26,687 ±0.18% | 30,091 ±0.21% | 1.13x

schleyfox and others added 2 commits January 19, 2024 17:01
All calls to the datetime constructor that pass an offset (o), have just
computed that offset (quickDT, fromObject) except for clone(). Clone
passes an "old" option to determine whether previous offset can be
reused. If we have config.o, but config.old is not set, then we can use
o without computing it.

This saves an expensive call to zone.offset that duplicates work that
was done immediately prior.
Copy link

linux-foundation-easycla bot commented Jan 22, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@schleyfox schleyfox changed the title Benjamin integ use computed offset Perf: Use computed offset passed in DateTime constructor Jan 22, 2024
@schleyfox schleyfox marked this pull request as ready for review January 22, 2024 16:50
@schleyfox
Copy link
Contributor Author

/easycla

@icambron icambron merged commit 343b061 into moment:master Mar 9, 2024
1 check passed
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.

2 participants