[antlr-interest] my brief thoughts on performance
doctlo-antlr at yahoo.com
doctlo-antlr at yahoo.com
Thu Feb 24 17:14:23 PST 2005
On Thu, 24 Feb 2005 16:44:24 -0800, you wrote:
>Next, I agree that much can be done to increase speed by tailoring the
>lexer methods like LA and so on to be suitable for your application.
>Even in general I think much could be done. I looked at it last year
>when Sriram S. told me that he got a huge improvement, but I didn't see
>an obvious way to be general and do what he did. The conclusion I have
>for 2.x is that you must rely on non-general user modifications to make
>it go fast; i.e., you have to do the tweaks, but perhaps we can
>summarize some useful tweaks. Perhaps a quick change to the code
>generators will allow caching of LA(i).
OK. I haven't been looking at the debate about LA closely and I don't
know the internals of Antlr generated code and the Antlr libraries
that well yet, but has anyone tried had tweaking code to memoise LA?
class Whatever
{
private static Token cache["k"];
public Token LA(int i)
{
Token retval=cache[i];
if(retval==null)
{
retval= LA_internal(i);
cache[i]=retval;
}
return retval;
}
public void consume()
{
int i;
for(i=0;i<"k";i++)
cache[i]=0;
consume_internal();
}
};
PS: My Java is not so hot either but should be good enough to get the
point across.
Thaddeus L. Olczyk
More information about the antlr-interest
mailing list