I’m getting odd sorting behavior in V8 7.5. Are there any known bugs?
-
-
Replying to @rauschma
No. Most often when folks see unexpected behavior, they’re using an inconsistent comparison function. What are you doing exactly?
2 replies 0 retweets 0 likes -
Replying to @mathias
Possibly something inconsistent. I suspect that my sorting function is not transitive (and that that matters): https://gist.github.com/rauschma/aed457de428a3935d941424f63830b84 … Fascinating that I only now accidentally produced data that exposes this issue.
1 reply 1 retweet 0 likes -
Replying to @rauschma
Could you include the input, so running the code shows the surprising behavior?
2 replies 0 retweets 0 likes -
Replying to @mathias
That’ll take longer – it’s a lot of data. I think it’s easier if I try to fix the sorting function and then see if it works. If there are still issues, I’ll create a small repro example. Thanks for your help so far – I think your tweet put me on the right track.
1 reply 0 retweets 0 likes -
Replying to @rauschma
Mathias Bynens Retweeted Mathias Bynens
FWIW, thinking about it this way helped me understand it better:https://twitter.com/mathias/status/1042669862663929858 …
Mathias Bynens added,
Mathias BynensVerified account @mathiasReplying to @kaelig @marcbaumbachActually, something else is going on here. For arrays with ≤ 10 elements,@v8js’s sort has always been stable. The problem in this case is the inconsistent comparison function: - if you compare 'Bar' with 'Foo' you get -1 - but if you compare 'Foo' with 'Bar' you get 01 reply 0 retweets 2 likes -
Replying to @mathias
Inverting the operands is what I got right AFAICT. My case is even trickier: cmp(a, b) → -1 cmp(b, c) → -1 cmp(a, c) → +1
1 reply 0 retweets 1 like -
Fixed it – transitivity FTW!
Thanks for your help!2 replies 0 retweets 3 likes
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.