-
Notifications
You must be signed in to change notification settings - Fork 30k
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
test: use a valid comparefn for sort #23000
Conversation
According the the ES spec a valid comparefn returns a negative number, zero, or a positive number. The behavior of returning a boolean is also not consistent among JS engines.
#22992 has an alternative change. We need to decide between them. |
Thanks @richardlau, that explains my test results. The D8 version I tested with was from the 7.x series. I gave my opinion in the other PR, but to re-state it here: I don't see any other usages of localeCompare in the test code, so I'm not sure that we want to introduce one now. |
Kicked off a CI: https://ci.nodejs.org/job/node-test-pull-request/17355/ |
Quick microbenchmark - the explicit compare seems much quicker across engines, fwiw. Chakra makes an attempt to cache localeCompare results (we took a known speed regression in RS5 with the switch to ICU, which is why the JSVU version of chakra is almost equal):
|
I don't think the perf difference is too important for this scenario, so I'll close my PR in favor of #22992. That one is a lot easier to read as an example. |
According the the ES spec a valid comparefn returns a negative number,
zero, or a positive number. The behavior of returning a boolean is also
not consistent among JS engines.
For example:
Interestingly D8 and node-v8 disagree (EDIT: this is because of the Timsort introduction in V8 7.0):
With the updated compare function everyone agrees:
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes