[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
SableCC Compiler Generation can be made more than twice as fast with a
very simple change!
-- here's why:
The rightside(int index) method in Production.java is throwing
gazillions of ArrayIndexOutOfBoundsExceptions (by design, apparently).
The exceptions are caught by the caller, and the specific exception type
is ignored. HOWEVER, creating these exceptions is fairly complicated,
because it involves creating strings, stringbuffers, exceptions,
-- here's how:
at the top of Production.java, under the line:
private static Production productions_;
add the line:
private static ArrayIndexOutOfBoundsException cachedException = new
in the method rightside(int index), add the lines:
if (index >= rightside.size())
before the existing line:
return (Symbol) rightside.get(index);
That's it! Twice as fast (or much more, depending on grammar) with the
addition of three lines!
If anyone is interested in further optimizing Sable, here's some
information that may help:
Sable is creating hundreds of thousands of NFA$State, NFA$Transition,
int, and Object. Some of these are undoubtedly necessary for
correctness and/or code cleanliness. Many probably are not.
The fact that AnalysisAdapter.setIn and AnalysisAdapter.setOut (which
are used everywhere during compiler generation) uses a TreeMap (which is
a very heavy datastructure) also is hurting performance. Switching to
an ObjectDepthFirstAdapter (I'm working on it) instead of setIn and
setOut would probably (?) help tons too.