-
Notifications
You must be signed in to change notification settings - Fork 632
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
localeCompare extremely slow sometimes #867
Comments
The following can be executed locally without the need of a RN app:
The results are shocking:
|
Yeah. Thanks for that additional demo. So it seems there are two different symptoms here:
|
It is interesting that this is reproducible both on MacOS and Android, since on Android localeCompare forwards to a Java implementation, while on MacOS it uses CoreFoundation. It appears that both are quite slow. |
I did some quick profiling on macOS, which suggests there is likely some low hanging fruit for optimisation. Specifically, with Intl disabled, I see most of the time being spent in
So it seems like we could achieve a dramatic speedup if we:
|
I have also bumped into this situation in react native using hermes. I had a list of objects which needed to be sort in locale.
it would take few seconds to finish sorting for 1000 items. When changed to this:
it would be over really fast. I haven't messured times but it is super fast compared to localeCompare. Also I noticed if I leave the locale in localeCompare it is working just as fast as collator:
So i guess there are some optimizations for default locale, probably the collator is reused when using default locale. Anyway I wrote this just if it can help to track the issue and give more insight. |
Bug Description
gradle clean
and confirmed this bug does not occur with JSCHermes version: (whatever's in RN 0.70.6)
React Native version (if any): 0.70.6 (the current latest)
OS version (if any): Android 13
Platform (most likely one of arm64-v8a, armeabi-v7a, x86, x86_64): arm64-v8a
Steps To Reproduce
npx react-native run-android
.String.prototype.localeCompare
taking multiple seconds each. For example:Those extremely slow calls are rare relative to the total number of calls. But because they're so extremely slow, they account for most of the total time — about 75% of the whole sort in this example.
code example
The repro repo above just consists of a fresh React Native app on the latest version (from
npx react-native init
), with the following code added at the top of the render function:That is, it makes up a long list of boring short alphabetic strings, and sorts them. The comparator just calls
String.prototype.localeCompare
, and times the call.The Expected Behavior
Calling
localeCompare
on a string should be fast — certainly far less than a second, for any non-gigantic strings.Other notes
I do not reproduce the issue when running in an emulated Android device, on x86_64. So it may be architecture-dependent.
The text was updated successfully, but these errors were encountered: