cjheath / treetop

A Ruby-based parsing DSL based on parsing expression grammars.
https://cjheath.github.io/treetop
MIT License
305 stars 22 forks source link

Parsing performance deterioration since 1.5 #40

Open snecklifter opened 4 years ago

snecklifter commented 4 years ago

Hello,

As per https://github.com/asciidoctor/asciidoctor-pdf/pull/1339

I am wondering if there is a reason for the performance degradation seen in asciidoctor-pdf and if this is something that can be easily fixed?

cjheath commented 4 years ago

There is very little runtime difference between these Treetop versions. The only thing I can point to that might make a tiny difference is that SyntaxNodes now store a reference to their parent node, at the point where that parent node gets instantiated. That will increase storage a small amount and take a tiny bit longer. It's hard to see that this could be responsible for your issues, but it's not likely to get reversed. It's just too hard to debug a Treetop grammar and to issue sensible error messages when it's not possible to see a Node's context.

mojavelinux commented 4 years ago

We've decided to accept this change. The performance degradation is measurable, but compared to other operations performed in the application, insignificant. And your reasoning for why it must be this way is understandable.

There's one other difference I notices when I generate the grammar with 1.6 instead of 1.5. Sometimes, the node extends the same type twice:

r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
r0.extend(Complex0)
r0.extend(Complex0)

I would think the generator would check for this. Let me know if you think that is a valid concern and thus need me to file a separate issue.