Using CGLIB to speed up XML parsing
October 21st, 2003
Good stuff from Chris Nokleberg… using CGLIB to make SAX parsing zippy:
For validated documents this is safe and gives a 3X speedup.
I don’t think I’d be likely to use the if/else if/else if structure that he mentions, because that seems like the kind of thing that is screaming out for separate objects. I believe Fowler even has a refactoring for this, but it’s too early in the morning to recall which one.


You’re kind of constrained by the nature of SAX. I think the common refactoring here is to map from element names to finer-grained methods by putting Method objects into a Map and invoking via reflection. Which, of course, is even slower.