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 upFix performance issue with List.sortBy #631
Conversation
jvoigtlaender
referenced this pull request
May 29, 2016
Closed
List.sortBy has serious performance issue #485
lukewestby
added
the
performance
label
Sep 12, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
jvoigtlaender commentedMay 29, 2016
The issue fixed here is as follows, testable at http://elm-lang.org/try.
The following program:
needs, in the browser on my machine, almost 4 seconds after each button click to show the new result. (The time taken, in milliseconds, will be printed as the first component of the pair in the button text.)
The problem is that
fis called far too often on individual elements oflist.By just swapping in the following definition instead of the current
List.sortBy:the 4 seconds from above are reduced to well under 1 second.
This is not just about a constant factor time difference. By changing
fand/orlist, the "old"List.sortBycan be arbitrarily (even asymptotically) more expensive than the "new" version. The converse is not true. The new implementation is guaranteed to never be asymptotically worse than the currentList.sortBy.The new version is also how the equivalent functionality is implemented in the Haskell standard library.
This pull request makes it so that Elm's
List.sortByuses the more efficient implementation.