Skip to content
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: Add DateTime.buildFormatParser and DateTime.fromFormatParser #1582

Merged
merged 1 commit into from
Mar 9, 2024

Conversation

schleyfox
Copy link
Contributor

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

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.

In benchmarks, this speeds up parsing by 4.4x
Copy link

linux-foundation-easycla bot commented Jan 22, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: schleyfox / name: Ben Hughes (b56224e)

@schleyfox schleyfox changed the title Add DateTime.buildFormatParser and DateTime.fromFormatParser Perf: Add DateTime.buildFormatParser and DateTime.fromFormatParser Jan 22, 2024
@schleyfox schleyfox marked this pull request as ready for review January 22, 2024 16:50
@schleyfox
Copy link
Contributor Author

/easycla

@icambron icambron merged commit 69032e6 into moment:master Mar 9, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants