Skip to content

Performance regression in mwc-random since 7.0.x

I've had a report that the performance of the mwc-random package has regressed seriously after upgrading from GHC 7.0 to 7.4. It turns out that 7.2 also has the regression.

Here's a sample program.

import qualified Data.Vector.Unboxed as U

import qualified System.Random.MWC as R
import System.Random.MWC.Distributions (standard)

count = 1000 * 1000

fast gen = standard gen

slow gen = standard gen >>= return

-- Edit this to choose fast or slow.
which gen = slow gen

main = do
  gen <- R.create
  v <- U.replicateM count (which gen)
  print (U.last v)

With GHC 7.0.3 -O2, this runs in 0.294 sec, regardless of whether fast or slow is used.

Under 7.4, fast runs in 0.062 sec (a nice speedup!), but slow now takes 9.2 sec (yikes!).

Roman suggested compiling the slow version with -fno-state-hack, which brings performance back up to 0.062 sec.

Edited by Ben Gamari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information