haskell / happy

The Happy parser generator for Haskell
Other
276 stars 84 forks source link

Use Elkhound's techniques to optimize the GLR mode #72

Open DemiMarie opened 8 years ago

DemiMarie commented 8 years ago

The GLR mode of Happy is likely to be slow. Fortunately, the problem of speeding it up has already been solved by Elkhound, which can generate parsers in C++ or OCaml.

simonmar commented 8 years ago

This isn't a particularly useful bug report. "Likely to be slow" - why? Have you benchmarked it? I'm inclined to close this without more details.

ghost commented 2 years ago

the reference seems to be to this code

https://github.com/WeiDUorg/elkhound

andreasabel commented 2 years ago

See also:

Tom Ridge. Simple, functional, sound and complete parsing for all context- free grammars. In International Conference on Certified Programs and Proofs, pages 103–118. Springer, 2011.

From Conclusions (section 12):

The time complexity of the memoized version of our algorithm is O(n^5). Real-world performance comparisons on the grammar E -> E E E | "1" | ǫ indicate that we are faster than the popular Happy parser generator running in GLR mode across a wide range of inputs.

Page 14:

parsers generated by Happy in GLR mode appear to be O(n^6) although GLR is theoretically O(n^3) in the worst case.

Screenshot 2022-03-07 at 08 08 17
DemiMarie commented 2 years ago

There is also an algorithm called BRNGLR that achieves worst-case O(n³).