luxon icon indicating copy to clipboard operation
luxon copied to clipboard

Perf: Add DateTime.buildFormatParser and DateTime.fromFormatParser

Open schleyfox opened this issue 1 year ago • 2 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 allows constructing a parser for a locale/format and reusing it when parsing dates. Without this, DateTime.fromFormat constructs a new parser on every call. When parsing large amounts of date strings, this gets rather slow.

Benchmark Comparison (name | before | after | after/before):

DateTime.fromFormat | 60,666 ±0.17% | 61,000 ±0.17% | ~
DateTime.fromFormat with zone | 26,687 ±0.18% | 26,688 ±0.21% | ~
DateTime.fromFormatParser |		| 402,199 ±0.13%
DateTime.fromFormatParser with zone |		| 45,206 ±0.22%

fromFormat vs. fromFormatParser | 60,666 ±0.17% | 402,199 ±0.13% | 6.63x
fromFormat vs fromFormatParser with zone | 26,687 ±0.18% | 45,206 | 1.69x

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 (b56224e0a7f5cfa402750cfd3a96e911f8230157)

/easycla

schleyfox avatar Jan 22 '24 20:01 schleyfox