Visitor Optimization Revisited – Realizing Traversal Graph Pruning by Runtime Bytecode Generation
Visitors and Rewriters are a well-known and powerful design pattern for processing regular data structures in a declarative way, while still writing imperative code.
The authors’ umod model generator creates Java data models from a concise and algebraic notation, including code for visitor skeleton classes according to traversal annotations.
User visitors are derived from these, overriding selected generated methods with payload code. All branches of the visiting trajectory that are not affected can thus be safely pruned according to control flow analysis.
In the first version (Lepper, Trancón 2011}, the pruning was implemented by dynamic case distinction. Here we have developed a new solution employing code generation at runtime.