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: Cache ts offset guesses for quickDT #1579

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

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
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

icambron commented 8 months ago

Looks pretty good. Just requested a few changes

schleyfox commented 8 months ago

Changed, thanks!

icambron commented 6 months ago

@schleyfox if you fix the conflicts, I'll merge this

schleyfox commented 6 months ago

@icambron conflicts fixed. thanks.