Table of Contents
This section contains a lot of accumulated lore about using Happy.
How to make your parser go faster:
If you are using GHC, generate parsers using the
-a -g -c options, and compile them using GHC with
-fglasgow-exts option. This is worth a
lot, in terms of compile-time,
execution speed and binary size .
The lexical analyser is usually the most performance critical part of a parser, so it's worth spending some time optimising this. Profiling tools are essential here. In really dire circumstances, resort to some of the hacks that are used in the Glasgow Haskell Compiler's interface-file lexer.
Simplify the grammar as much as possible, as this reduces the number of states and reduction rules that need to be applied.
Use left recursion rather than right recursion wherever possible. While not strictly a performance issue, this affects the size of the parser stack, which is kept on the heap and thus needs to be garbage collected.
 omitting the
-a may generate slightly faster parsers,
but they will be much bigger.