[Haskell-cafe] [GHC 7.8.4] IO Monad leak space?

Baojun Wang wangbj at gmail.com
Fri Jul 3 16:16:03 UTC 2015


few more points:

- In function f2/f3 I use a local function ``go'' instead of loopM_, it
turns out that local ``go'' function is much faster than loopM_ (loopM_ is
still faster than mapM_);
- If I add a signature for loopM_ ( loopM_ :: (Int -> IO ()) -> Int -> Int
-> Int -> IO () ), then the program runs noticeable slower even profiling
is turned off;

These really looks odd to me, and I think it really makes optimization
painful.


On Fri, Jul 3, 2015 at 9:06 AM Baojun Wang <wangbj at gmail.com> wrote:

> Full source code:
>
> https://github.com/wangbj/haskell/blob/master/lcmsum.hs
>
> I build the program with:
>
> ghc -O2 --make -rtsopts -prof -auto-all lcmsum
>
> and run it with:
>
> echo -ne '5\n100\n1000\n10000\n100000\n1000000\n'  | ./lcmsum +RTS
> -sstderr -p
>
> I've tried use
>
> ``let !ret = (v1+(fromIntegral i) * (fromIntegral v)) in r'' instead,
> however it didn't make any difference per profiling. (both Array are
> Unboxed).
>
> Thanks
> baojun
>
>
> On Fri, Jul 3, 2015 at 2:50 AM Tom Ellis <
> tom-lists-haskell-cafe-2013 at jaguarpaw.co.uk> wrote:
>
>> On Fri, Jul 03, 2015 at 08:18:55AM +0000, Baojun Wang wrote:
>> > Consider below function:
>> >
>> > f3 :: UArray Int Int -> IOUArray Int Int64 -> Int -> IO ()
>> > f3 u r i = let !v = u ! i
>> >             in go (f31 v) i i
>> >   where f31 v j = readArray r j >>= \v1 ->
>> >           writeArray r j (v1 + (fromIntegral i) * (fromIntegral v))
>> >         f31 :: Int -> Int -> IO ()
>> >         go g k s = when (k <= maxn) (
>> >           g k >> go g (s+k) s )
>> >
>> > When call f3:
>> >
>> >   loopM_ (f3 uu res) 1 1 1000000
>>
>> Could you provide complete working code (including definitions of uu and
>> res) and I will have a go at diagnosing.  (My first guess is that you need
>> to force (v1 + (fromIntegral i) * (fromIntegral v)).)
>>
>> Tom
>> _______________________________________________
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20150703/d9cc4030/attachment.html>


More information about the Haskell-Cafe mailing list