-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Perf: Cache ts offset guesses for quickDT #1579
Perf: Cache ts offset guesses for quickDT #1579
Conversation
/easycla |
src/datetime.js
Outdated
function guessOffsetForZone(zone) { | ||
if (!DateTime._zoneOffsetGuessCache[zone]) { | ||
if (DateTime._zoneOffsetTs === undefined) { | ||
DateTime._zoneOffsetTs = Settings.now(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should support clearing the cache here
test/datetime/dst.test.js
Outdated
expect(d.hour).toBe(1); | ||
expect(d.offset).toBe(-4 * 60); | ||
|
||
DateTime._zoneOffsetGuessCache = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could then use the resetCaches() function in here
Looks pretty good. Just requested a few changes |
Changed, thanks! |
@schleyfox if you fix the conflicts, I'll merge this |
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
a479dfe
to
f7d747d
Compare
@icambron conflicts fixed. thanks. |
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 #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
):