-
Notifications
You must be signed in to change notification settings - Fork 1.4k
new DurationFormat is very slow on React Native / Hermes #4936
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
Comments
Looking into this a bit more, during a single instantiation of Some quick optimizations, like memoizing |
Thanks for reporting. I'll take a look. Polyfills have traditionally been more locale-data-bound than CPU bound, so for polyfills where the dataset is small we ship them w/ everything. |
I’ve seen this issue in older Mono repos. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I use this abomination (once, as early as possible) to remove all the locales I don't need:
This function directly mutates the |
Which package?
Describe the bug
Instantiating instances of
DurationFormat
is very slow on React Native / Hermes:Output:
I believe #4522 is likely the same issue.
Screenshots
This flamegraph is a little rough but demonstrates where the cost is going:
Smartphone:
Investigation
Locale matching is known to be particularly slow on React Native / Hermes (#4276). Because of this, caching of Intl objects is recommended.
Unfortunately, the instantiation of even one instance of
DurationFormat
heavily impacts performance, taking about 600 ms on my machine.The reason appears to be due to
DurationFormat
passing 700+ locales as theavailableLocales
argument toResolveLocale
. Other Intl objects likeNumberFormat
orListFormat
do not have this problem because the set of available locales is opt-in via imports of locale-data.DurationFormat
appears to be unique in that all locale data is automatically made available (probably in time-separators.generated.ts)?The text was updated successfully, but these errors were encountered: