luxon
luxon copied to clipboard
Perf: Use computed offset passed in DateTime constructor
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
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: schleyfox / name: Ben Hughes (def2eac1eb90efb933f1db20d1b7039f1c668ff2, 5fa43cd5a8b219ff31d3f97d68164dfeec7aae0f)
/easycla