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: Memoize digitsRegex #1581

Merged

Conversation

schleyfox
Copy link
Contributor

@schleyfox schleyfox commented Jan 22, 2024

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 #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

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.

Benchmarks show about a 1.5x improvement on DateTime.fromFormat
Copy link

linux-foundation-easycla bot commented Jan 22, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@schleyfox schleyfox changed the title Memoize digitsRegex Perf: Memoize digitsRegex Jan 22, 2024
@schleyfox schleyfox marked this pull request as ready for review January 22, 2024 16:50
@schleyfox
Copy link
Contributor Author

/easycla

@moh-incom moh-incom mentioned this pull request Mar 5, 2024
@icambron icambron merged commit 6b0ec2e into moment:master Mar 9, 2024
2 checks 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