3

What are the standard methods to profile parser written in parser combinator libraries in Haskell?

I'm currently using uu-parsinglib but I would be very interested in knowing the methods of profiling also other parser combinator libraries like Parsec.

Right now I have written my parser and it is slow and eats a lot of ram (for 600 lines input text it takes about 5 seconds to parse with more than 1Gb of RAM and I want to investigate how I can improve it)

Wojciech Danilo
  • 11,573
  • 17
  • 66
  • 132
  • 1
    You using, String and List types? That can be really memory intensive. – TallerGhostWalt Aug 19 '13 at 04:41
  • "My program is slow and eats XXX GB of RAM given small import" usually implies a laziness bug somewhere. This might not be anything to do with your _parser_, but instead is related to how you use the result of the parse. – MathematicalOrchid Aug 19 '13 at 07:24
  • @MathematicalOrchid: I'm siply printing the AST to the terminal – Wojciech Danilo Aug 19 '13 at 09:35
  • @TallerGhostWalt: What should I use instead? – Wojciech Danilo Aug 19 '13 at 09:36
  • 1
    @danilo2 Can you post any code, or maybe a small working example? It's really hard to guess what's wrong with a program without knowing more about it. Considering your input data is a mere few kilobytes, your in-memory data structure probably should be about the same size. If you're using up that much memory, it means you're doing something wrong. Can you try some smaller inputs to find which conditions trigger the massive memory and time use? – bheklilr Aug 19 '13 at 15:22
  • 1
    Have you tried the built-in GHC profiler? – n. m. could be an AI Aug 19 '13 at 19:14

1 Answers1

2

Try heap profiling:

$ ./prog +RTS -K128M -hc -p 
$ hp2ps -c prog.hp

If the profile looks like a mountain and is in the megabytes, probably you construct a large data structure first and then reduce it (and then could look into using accumulators or memoization).

More detailed info: http://book.realworldhaskell.org/read/profiling-and-optimization.html

jev
  • 2,023
  • 1
  • 17
  • 26