luxon
luxon copied to clipboard
Perf: Memoize digitsRegex
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.
Profiles reveal that a substantial portion of fromFormat time is spent in digitsRegex. It is only called from unitsForToken and it is always called with 11 suffixes to match different numbers of digits.
There are 21 numbering systems, so a fully expanded cache would hold 11*21 = 231 regexes.
This is related to https://github.com/moment/luxon/pull/1530 , but involves a much more restricted cache
Benchmark Comparison (name | before | after | after/before
):
DateTime.fromFormat | 60,666 ±0.17% | 113,218 ±0.20% | 1.87x
DateTime.fromFormat with zone | 26,687 ±0.18% | 33,563 ±0.19% | 1.26x
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: schleyfox / name: Ben Hughes (3e363ee6a729735c8ec5cdf52827ff2840d4337d, 297b398cd4d8a83af370b60403997ab69ccd9c24)
/easycla