[Haskell-beginners] Understanding program stack usage
Rafael Gustavo da Cunha Pereira Pinto
RafaelGCPP.Linux at gmail.com
Wed Apr 27 21:06:27 CEST 2011
GHC profiling is not that hard. There are a few tutorials on the Internet
that can help you (try Real World Haskell, ch
25<http://book.realworldhaskell.org/read/profiling-and-optimization.html>)
Running your code with "+RTS -pa -sstderr" can give you some hints on where
it is hogging memory.
Regards.
Rafael
On Wed, Apr 27, 2011 at 15:25, Patrick LeBoutillier <
patrick.leboutillier at gmail.com> wrote:
> Felipe,
>
> I tried the $! bit, but I get the same result. I guess there's another
> leak somewhere...
>
> Patrick
>
> On Wed, Apr 27, 2011 at 11:20 AM, Felipe Almeida Lessa
> <felipe.lessa at gmail.com> wrote:
> > On Wed, Apr 27, 2011 at 11:52 AM, Patrick LeBoutillier
> > <patrick.leboutillier at gmail.com> wrote:
> >> How do I figure out why the program needs a lot of stack?
> >
> > Usually it is because you are building a large thunk.
> >
> >> Also, is there an easy way to increace performance?
> >
> > Getting rid of the thunks should increase performance as well.
> >
> > I've had just a quick look on your code, but here are some suggestions:
> >
> >> record :: (Ord n) => n -> Distrib n -> Distrib n
> >> record n (Distrib m rs) = Distrib (M.alter f slot m) rs
> >> where f (Just n) = Just $ n + 1
> >> f Nothing = Just 1
> >> slot = findSlot n rs
> >> findSlot x (r@(Range a b):rs)
> >> | x >= a && x < b = r
> >> | otherwise = findSlot x rs
> >> findSlot x [] = OutOfBounds
> >
> > Try changing "Just $ n + 1" to "Just $! n + 1". It is possible that
> > this change alone removes the leak (it is the only obvious leak I'm
> > seeing right now).
> >
> > Also, for findSlot you may want to do a binary search, but that isn't
> > related to the leak at all.
> >
> > Cheers,
> >
> > --
> > Felipe.
> >
>
>
>
> --
> =====================
> Patrick LeBoutillier
> Rosemère, Québec, Canada
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Rafael Gustavo da Cunha Pereira Pinto
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110427/cb8fd67d/attachment.htm>
More information about the Beginners
mailing list