[antlr-interest] Performance and LA(int)

Richard Matthias richard at exaflop.org
Wed Feb 23 16:53:01 PST 2005


> For C# code generation, LA(1) and LA(2) are cached in 
>*lexers*. This resulted in noticeably better performance. Our 
>basic performance tests suggested that caching LA1/LA2 in 
>parsers (in addition to lexer caching) didn't always result in 
>better performance. Depends on the grammar it seems.
>Weird or what?
>
>Micheal


I was going to suggest that it's a shame LLkParser.LA() can't be final/sealed
- it only gets overriden by the debug parsers which doesn't seem like a very
good reason to slow down production code. Then I started actually reading the
code and there's a heck of a lot going on when you call LA() even if you only
expect to get the same result back each time. Really, final or virtual,
there's no chance of it getting inlined, lets put it that way. The code was
written by someone who loves OO principles far more than performance.

I'm interested that you didn't always get a speedup in the parser by caching
the result of LA(). Still, I'd have left the code in there - it's not going
to do any harm either way.

Richard



More information about the antlr-interest mailing list