[antlr-interest] predicates, performance, and C++, oh my!
Bryan Ewbank
ewbank at gmail.com
Tue Jun 28 09:52:13 PDT 2005
Wanted to let others learn from our pain...
We have quite a few predicates, and we've built them up so they are
simple to read, like this:
myRule :
( TOKEN_ONE ) => ruleONE
| ( TOKEN_TWO ) => ruleTWO
| ( TOKEN_TRE ) => ruleTRE
| /* whatever else */
;
As it turns out, there's an exception thrown/caught for each of the
predicates (of course; i'd forgotten it, though), which means there's
a substantial hit if the predicates don't match (3 exceptions thrown).
By rewriting it to use only one predicate, we greatly improved thruput:
myRule :
( TOKEN_ONE | TOKEN_TWO | TOKEN_TRE )
=> ( ruleONE | ruleTWO | ruleTRE )
| /* whatever else */
;
You might still need extra goo in the first subrule, but you only get
one exception thrown for the unmatched case, which really helps.
Of course, YMMV, but every little bit should help someone.
- Bryan
More information about the antlr-interest
mailing list