[antlr-interest] Little speed increases

agno at ai.sri.com agno at ai.sri.com
Mon Nov 12 11:18:51 PST 2001


I've been using the 2.7.1 version of ANTLR for Java, and I thought I
should mention that while I was looking for tiny speed increases, I
found that loops were being used to copy arrays instead of
System.arraycopy.

This was in:
CharQueue.expand():
System.arraycopy(buffer, offset, newBuffer, 0, buffer.length - offset);
System.arraycopy(buffer, 0, newBuffer, buffer.length - offset, offset);

TokenQueue.expand():
System.arraycopy(buffer, offset, newBuffer, 0, buffer.length - offset);
System.arraycopy(buffer, 0, newBuffer, buffer.length - offset, offset);

ANTLRStringBuffer.append(char)
System.arraycopy(buffer, 0, newBuffer, 0, length);

When I changed these to use arraycopy, it gave me a fraction of a
millisecond increase in time (on average) to parse a single line,
which was helpful in my application.  I also made some changes so that
one could reuse a lexer and a parser, but they're only useful when you
only have one thread accessing them.  I'm not sure if there was a
difference there or not--possibly my machine was too fast to detect one.

Andrew.



 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list