Opened 3 years ago

Closed 2 years ago

#9073 closed bug (worksforme)

small SPECIALIZE INLINE program taking gigabytes of memory to compile

Reported by: dagit Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.8.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


I have a small program that is taking 1+ GB of memory to compile.

I've distilled the troublesome input down to the following:

{-# LANGUAGE BangPatterns #-}
import Data.Vector

knot :: Vector Double -> Int -> Double
knot vs k = vs ! idx0
  !idx0 = abs k `mod` 16
{-# SPECIALIZE INLINE knot :: Vector Double -> Int -> Double #-}

noise :: Vector Double -> Int -> Double
noise vs k =
  knot vs k + knot vs k + knot vs k + knot vs k +
  knot vs k + knot vs k + knot vs k + knot vs k

Compiled with ghc -fprof-auto -prof -O2 -Wall. As far as I can tell, prof-auto, prof, and optimizations of at least -O1 are required to trigger it.

I'm using ghc-7.8.2 64bit for Windows. vector is version (currently the latest on hackage). Same code worked fine on ghc 7.6.2.

Also worth noting: Even though the SPECIALIZE isn't needed, if you remove the SPECIALIZE or the INLINE the problem goes away. If you remove even one of the duplicated calls to knot vs k in the body of noise then the amount of memory required drops dramatically. Add more to increase the requirements. I've been able to push it up around 10 GB, but I don't have enough memory to test beyond that!


Change History (2)

comment:1 Changed 3 years ago by dagit

Adding -fno-full-laziness makes the problem go away (that is, the memory usage goes back to normal).

comment:2 Changed 2 years ago by thomie

Resolution: worksforme
Status: newclosed

Thanks for the report. I can replicate the problem with 7.8.3. It seems to be fixed in HEAD, so please wait for 7.10 to come out, or try with 7.8.4 in a few weeks.

Note: See TracTickets for help on using tickets.