-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix TimeZone.p.getXxxTransition() worst-case perf
When passed vary far-past or far-future dates, `TimeZone.p.get(Next|Previous)Transition()` would take minutes of 100% CPU to finish. This commit improves worst-case perf more than 1000x by: * Skipping looping for any dates before 1847 CE, which is the first entry in the TZDB. * Optimizing handling of dates 10 years or later than the current system time. Offset changes are only planned a few years in advance, so when povided a far-future date, we only need to check one year away to see if there's DST projected forward from the most recent rule in that TZ. If there's not, then when calling `getPreviousTransition` we can skip all the way back to current time + 10 years because no transitions will be in the skipped period. These optimizations reduce a worst-case loop of over 200K years to under 200 years, for a more-than-1000X worst-case perf improvement.
- Loading branch information
1 parent
30c4d4d
commit dcbadd7
Showing
2 changed files
with
142 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters