luxon icon indicating copy to clipboard operation
luxon copied to clipboard

Perf: Cache ts offset guesses for quickDT

Open schleyfox opened this issue 1 year ago • 4 comments

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

schleyfox avatar Jan 22 '24 16:01 schleyfox

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: schleyfox / name: Ben Hughes (f7d747dae540f00db23c7219e678e3ea60c576f5, 51427eff2cfb71f873d9c4ddff1675265217652a)

/easycla

schleyfox avatar Jan 22 '24 20:01 schleyfox

Looks pretty good. Just requested a few changes

icambron avatar Jan 22 '24 22:01 icambron

Changed, thanks!

schleyfox avatar Jan 22 '24 22:01 schleyfox

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

icambron avatar Mar 09 '24 16:03 icambron

@icambron conflicts fixed. thanks.

schleyfox avatar Mar 09 '24 21:03 schleyfox