<div dir="ltr">Data.List.sortBy uses a DList-like representation to efficiently chunk a list, but the final conversion from DList to List is not strict. This leaves unnecessary suspensions while sorting. This was first noticed in <a href="https://github.com/ghc-proposals/ghc-proposals/pull/50">https://github.com/ghc-proposals/ghc-proposals/pull/50</a>, where sorting a random list with a naive merge sort is faster than the one in base.<div><br></div><div>Proposing the following change, which should improve performance and space usage.<br><br>```diff<br>diff --git a/libraries/base/Data/OldList.hs b/libraries/base/Data/OldList.hs<br>index c3618c42a9..a68c4f42af 100644<br>--- a/libraries/base/Data/OldList.hs<br>+++ b/libraries/base/Data/OldList.hs<br>@@ -851,7 +851,7 @@ sortBy cmp = mergeAll . sequences<br> <br>     ascending a as (b:bs)<br>       | a `cmp` b /= GT = ascending b (\ys -> as (a:ys)) bs<br>-    ascending a as bs   = as [a]: sequences bs<br>+    ascending a as bs   = <b>as [a] `seq`</b> as [a] : sequences bs<br> <br>     mergeAll [x] = x<br>     mergeAll xs  = mergeAll (mergePairs xs)<br>```</div><div><br></div><div><br></div><div>And, as a side note, can we please add more type signatures and comments to the sort/sortBy function?</div><div><br></div><div>Cheers,</div><div>Sid</div></div>