Skip to content

Squirrelly inliner behaviour leads to 80x slowdown

Recently, I switched the mwc-random package (http://hackage.haskell.org/package/mwc-random) over from running in the ST monad to using Roman's primitive package. I didn't notice initially, but this caused a huge performance regression.

mwc-random 0.4.1.1 uses ST internally, and runs the benchmarks/Quickie benchmark in 0.017 seconds.

mwc-random 0.5.1.3 uses PrimMonad internally, and takes 1.328 seconds to run the same benchmark.

That's about a factor of 80 slowdown. This causes a massive knock-on performance loss in packages such as criterion that need fast PRNGs.

The problem is very easy to reproduce:

cabal install mwc-random-0.4.1.1
cabal install mwc-random-0.5.1.3
darcs get http://darcs.serpentine.com/mwc-random/
cd mwc-random/benchmarks
ghc -fforce-recomp -O  -package mwc-random-0.4.1.1 --make Quickie -o quickie-411
ghc -fforce-recomp -O  -package mwc-random-0.5.1.3 --make Quickie -o quickie-513

time ./quickie-411
time ./quickie-513
Edited by Ian Lynagh -
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information