Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upList.sortBy has serious performance issue #485
Comments
jvoigtlaender
referenced this issue
Jan 17, 2016
Closed
minimumBy and maximumBy have serious performance issues #23
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
jvoigtlaender
Jan 17, 2016
Contributor
For comparison, see the Haskell standard library version of this function: https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-List.html#v:sortOn
|
For comparison, see the Haskell standard library version of this function: https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-List.html#v:sortOn |
This was referenced May 24, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Show comment
Hide comment
jvoigtlaender
May 29, 2016
Contributor
Replaced by pull request: https://github.com/elm-lang/core/pull/631.
|
Replaced by pull request: https://github.com/elm-lang/core/pull/631. |
jvoigtlaender
closed this
May 29, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jvoigtlaender commentedJan 17, 2016
Let's say I call
List.sortBy fon a list of length3, where the following is true:ffor any input is extremely expensive.That
List.sortByis reduced to a call of JavaScript'ssortfunction on arrays. I don't know what sorting algorithm JavaScript implementations use, but it doesn't really matter. What matters is that due to the wayList.sortByis currently reduced to JavaScript'ssort, the following is true:fis called at least four times. (It might even be six times.)Very bad! At least one time too many.
A better strategy would be (essentially, though in details this can be even further improved):
This new code is guaranteed to induce only three calls of
ffor an input list of length3.Since I can make
farbitrarily expensive to compute on certain arguments, I can give calls of the current implementation ofList.sortBythat are arbitrarily (even asymptotically) more expensive than the proposed alternative. (The converse is not true. The new implementation is guaranteed to not be asymptotically worse than the current implementation.)