Skip to content

Performance regression in 9.2.4 and 9.4.2 compared to 9.0.2

This is the code (adapted from this benchmark):

{-# LANGUAGE BangPatterns #-}

import Control.Parallel.Strategies
import Data.Word
import System.Environment

data Tree = Leaf Word32 | Node Tree Tree

unravel :: Int -> Tree -> [Tree]
unravel 0 x = [x]
unravel _ x@Leaf{} = [x]
unravel n (Node x y) = unravel (n - 1) x ++ unravel (n - 1) y

-- Creates a tree with 2^n elements
gen 0 = Leaf 1
gen n = Node (gen(n - 1)) (gen(n - 1))

-- Adds all elements of a tree
sun !s (Leaf x)   = x + s
sun !s (Node a b) = sun (sun s b) a

sun' :: Tree -> Word32
sun' = sum . parMap rseq (sun 0) . unravel 6

-- Performs 2^n additions
main = do
  n <- read.head <$> getArgs :: IO Word32
  print $ sun' (gen n)

Here are my timings for different ghc versions (compiled with -O2 -threaded and running with ./T5 30 +RTS -s -N8 on an 8 core machine):

GHC Total MUT GC
9.0.2 3.552s 1.577s 1.965s
9.2.4 21.721s 13.308s 8.399s
9.4.2 6.858s 4.378s 2.468s
Edited by Jaro Reinders
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information