moment / luxon

⏱ A library for working with dates and times in JS
https://moment.github.io/luxon
MIT License
15.32k stars 730 forks source link

Perf: Use computed offset passed in DateTime constructor #1576

Closed schleyfox closed 6 months ago

schleyfox commented 8 months ago

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 https://github.com/moment/luxon/pull/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
linux-foundation-easycla[bot] commented 8 months ago

CLA Signed

The committers listed above are authorized under a signed CLA.

schleyfox commented 8 months ago

/easycla