From e7c1e746187c2555a4fde6db0810b6441a804f87 Mon Sep 17 00:00:00 2001 From: Folkert Date: Fri, 8 Nov 2019 19:57:18 +0100 Subject: [PATCH] Fix #642 Bad performance/memory leak for long list literals A one-character fix that speeds up the formatting of long literals and drastically reduces memory usage. A very simple example is ```elm module Small exposing (x) x = [ 1, 2, 3 , 4] ``` But with a list literal of many thousands of elements. The newline forces all elements to get their own line. This is implemented as a fold, but in practice this would often perform ``` longList ++ shortList ``` By reversing the fold (from `foldl` to `foldr`) that turns into ``` shortList ++ longList ``` Which requires less traversals and memory. --- src/Box.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Box.hs b/src/Box.hs index 74bd45fd0..3f0645f66 100644 --- a/src/Box.hs +++ b/src/Box.hs @@ -119,7 +119,7 @@ stack1 children = [first] -> first boxes -> - foldl1 stack' boxes + foldr1 stack' boxes mapLines :: (Line -> Line) -> Box -> Box