
On Wed, Sep 10, 2008 at 12:31 PM, Vlad Skvortsov
Hmm, that's a good point! I didn't think about it. Though how do I make GHC link in profiling versions of standard libraries? My own libraries are built with profiling support and I run Setup.hs with --enable-library-profiling and --enable-executable-profiling options.
When you build your own code with -prof, GHC automatically links in profiling versions of the standard libraries. However, its profiling libraries were not built with -auto-all (the reason is that adding cost centres interferes with optimization). To build the libraries with -auto-all, you would need to build GHC from sources, which is not for the faint of heart. However, the results of doing that aren't usually very enlightening anyway -- for example, foldr might be called from many different places, but you might only care about a single call site (and then you can annotate that call site). Just from looking, I would guess this is the culprit:
termToStr t il = {-# SCC "termToStr" #-} ((:) ("t " ++ t ++ " " ++ (foldl ilItemToStr "" il)))
If you want to be really sure, you can rewrite this as: termToStr t il = {-# SCC "termToStr" #-} ((:) ("t " ++ t ++ " " ++ ({-# SCC "termToStr_foldl" #-} foldl ilItemToStr "" il))) and that will give you a cost centre measuring the specific cost of the invocation of foldl.
Data.Map.foldWith key is implemented with foldr[1], however I'm not sure I'm getting how foldr is superior to foldl here (foldl' I understand). Could you shed some light on that for me please?
I meant the call to foldl in termToStr. There's a good explanation of this at: http://en.wikibooks.org/wiki/Haskell/Performance_Introduction (look for "foldl"). Cheers, Tim -- Tim Chevalier * http://cs.pdx.edu/~tjc * Often in error, never in doubt Just enough: Obama/Biden '08.