luxon
luxon copied to clipboard
Perf: Cache ts offset guesses for quickDT
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
Previously we guessed by calling zone.offset(tsNow) on every construction of a date from date parts. This caches that result instead, saving a call to offset. The tests verify that this works across DST boundaries when the cache holds an offset for the previous DST state from now.
For processes that live across a DST boundary and mostly handle current date times, this will mean the guess is wrong and we'll have to re-guess. Since we're caching one call to offset, this should be performance neutral to current behavior. Otherwise, we save a call.
Benchmark Comparison (name | before | after | after/before
):
DateTime.local with numbers and zone | 50,913 ±0.18% | 66,168 ±0.25% | 1.3x
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: schleyfox / name: Ben Hughes (f7d747dae540f00db23c7219e678e3ea60c576f5, 51427eff2cfb71f873d9c4ddff1675265217652a)
/easycla
Looks pretty good. Just requested a few changes
Changed, thanks!
@schleyfox if you fix the conflicts, I'll merge this
@icambron conflicts fixed. thanks.