Hi there,


I was wondering if somebody could help me locating
a big space-leak.

Given the following functions:

> spaceLeak :: (Eq f,Show f) =>
>              [f] -> [f]
> spaceLeak fs
>   = seq' fs (trace (show fs') fs')
>   where fs' = leak fs

> seq' :: (Eq a) => a -> b -> b
> seq' a b
>   | a == a = b

I have profiled an application of (spaceLeak fs) for some fs
which were  small in size. Just before the application
of (spaceLeak fs), i.e. just after the (seq' fs) the heap
size is about 3 MB.

The computation of spaceleak fs takes about 120 seconds and
acccumulates some 15 odd additional MB of heap. The resulting
fs' again is very small in size (I printed them out with
trace). Nevertheless all the space accumutated in the
``leak fs'' seems to have leaked. After (spaceLeak fs) the
heap-size is the same as just before (leak fs) has
terminated. 

Because of the fact that a trace showed that a show of the
resulting fs' was ``small'' I can not understand what is
going on here.

I have done similar computations as described above
in Lisp before and never ran into space problems of
this size. Also the computatoion in Lisp took a lot less
time. [I find Integer arithmetic in ghc extremely slow (see
example appended at the end of this message). I am seriously
thinking of implementing my own Integer arithmetic.]

All my Haskell is standard ghc (2.0699999999999998). There
are no calls to funny libraries. The computation
``leak fs'' requires a lot of Integer arithmetic (big
numbers). Another application of mine which does a lot
of Integer number crunching suffers from similar problems.

I have been trying to locate the source of this leak for
weeks and still haven't found it. If there's anybody with
a good suggestion how to continue trying to find it, it
would be *GREATLY* appreciated.


Helplessly,


Marc van Dongen
________________________________________________________________
Marc van Dongen, Computer Science Dept | phone:   +353 21 903083
  National University of Ireland, Cork | Fax:     +353 21 903113
           College Road, Cork, Ireland | Email: [EMAIL PROTECTED]
________________________________________________________________

> module Main( main ) where
> test :: Integer -> Integer -> IO ()
> test i j
>   | i == j = return ()
>   | True   = test (i+1) j
> main = test 0 1000000

:!time sh -c 'Test 1000000'
3.74u 0.04s 0:03.87 97.6%

Reply via email to