Long rendering time for invalid input
Closed this issue · 5 comments
This looks similar to #18
The following snippet takes a very long time (> 10 seconds on my machine) to render:
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
*a
aaaaa
Yes. OK, the fix I proposed for #18 is not general enough. And I see that this input is also problematic for my other peg-based parser, lunamark.
What is needed is a way to avoid parsing Emph when you're inside an Emph environment (and similarly for Strong). But (unless I'm mistaken) the code parts of the PEG are not executed unless the parser matches. That means that we can't set a variable that says "I'm inside an Emph inline" that affects the Inline parsers inside the Emph.
There must be another solution, but it's not yet clear to me me what it is.
OK, I took a different approach. It changes the semantics slightly on edge cases, but it seems to get normal nested cases right.
Oddly, this change has a slight impact on performace (0.09 to 0.1 s on one benchmark). Not sure why.
Performance hit fixed by subsequent commit!
Nice! Thank you very much for fixing this so quickly!