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(@formatjs/intl-datetimeformat): cache number format instances in formatDateParts #4529

Conversation

Fox32
Copy link

@Fox32 Fox32 commented Sep 15, 2024

Closes #4510

Hey! As discussed in #4510, I noticed that calling DateTimeFormat.formatDateParts() creates new instances of NumberFormat on every call. As creating NumberFormat can be quite heavy due to the bestfit mode of LocaleMatcher (see #4276 for more details), it's best to cache NumberFormat instances.

To keep performance of the DateTimeFormat constructor as-is, I lazily initialize the three (sometimes just two) NumberFormat instances during the first call to formatDateParts and store them in the internalSlots of the DateTimeFormat.

I'm not 100% sure if internalSlots is the right place to store these internal instances, if not, let me know where I could store them instead.

Thanks!

@longlho
Copy link
Member

longlho commented Oct 8, 2024

this was fixed manually. Thanks for your contribution

@longlho longlho closed this Oct 8, 2024
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.

Performance issues with formatDateParts
2 participants