[antlr-interest] some quick codegen optimization thoughts
Terence Parr
parrt at cs.usfca.edu
Thu Mar 24 18:55:51 PST 2005
Howdy,
So I've spent some time implementing switches vs if-then-else chains
(in Java and bytecodes (yes, that was a pain)). Further, I have worked
on factoring out input.LA(1) calls. The code looks pretty clean I
think. I've been using the java.g grammar as a benchmark. The
decision making is optimal in that it references input.LA(k) at most
once per k value need to predict alternatives (both with if-then-elses
and switches; both in Java and in bytecodes).
The summary is this. Generating switches generates slightly bigger
code .class files. It seems to gain only about 10% in CPU time, which
ain't much given all the effort I just put in. ;) I'm guessing C and
other compilers will be able to take better advantage of my efforts. ;)
To give you a benchmark against 2.x ANTLR doing the same grammar (but
doing tree construction), ANTLR's generated parser is only about 2x as
fast, but that ain't too bad to start. I have one really major
optimization left to do (later) that should make it much better.
I'm rapidly closing in on a complete piece of software for an
early-release. Then I'll need some more sample grammars so people can
actually try it out. Still I'm thinking late May timeframe.
Ter
--
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