[antlr-interest] wow; talk about premature optimization

Terence Parr parrt at cs.usfca.edu
Wed Mar 30 15:43:48 PST 2005


This is pretty funny.  The fact that I have all this junk in ANTLR v3 
to generate/assemble bytecode etc... has been bugging me.  It's 
"unclean" and only needed for java.  I ran an experiment last night and 
today--I went back to generating pure Java for my cyclic DFA.  I have 
to use a method call to switch states whereas in bytecodes I can use a 
goto.  I expected this to be a huge win.  Turns out...drum roll...for 
large input there is no difference. ;)  most decisions are not cyclic 
and are generated efficiently in pure java.  There appears to be a 
small start up cost associated with the static DFA objects I have to 
create, but not that bad.

It was a MUCH bigger optimization to factor out LA(i) calls to 
store/use a temp value instead.  Switch generation also surprised me by 
buying us not that much.  C and such could get more from it so I'm 
leaving.  Java VMs probably just aren't too good at switches unless 
they are consecutive values.

So, I am tentatively switching back to pure java, no bytecodes.   
Apparently I did the bytecode stuff for "fun".  No biggie as I really 
wanted to learn how to gen .class files and generate bytecodes.  I'm 
well prepared for a grad programming class now. :)

CS Professor & Grad Director, University of San Francisco
Creator, ANTLR Parser Generator, http://www.antlr.org
Cofounder, http://www.jguru.com

More information about the antlr-interest mailing list