Description
Here's a somewhat radical patch that does two fundamental changes:
1. Token objects returned by the Parser that are normally carried around by AST Nodes are dropped completely or for the most part for many node types. This should be ok since Token is an internal structure. Tokens are typically dropped after node init so line/column numbering and other features should still work.
2. Interpolated image class variable carried around by the ASTStringLiteral is no longer kept around.
I ran some tests for large text intensive templates and according to Eclipse Memory Analyzer patched 2.0.0 version template memory consumption was 50-60% smaller than with Velocity 1.7. Analyzer also shows that there are some duplicate strings (e.g. #if) that could be avoided by adding some logic but I didn't do it yet.
I also removed string interning from the code since there have been some reports with big memory consumption after running Velocity for a while.
There's a test build if you want to try this out:
http://www.sci.fi/~jviinama/velocity/memoryboost/velocity-engine-core-2.0.0-SNAPSHOT.jar
Note that Velocity 2.0 handles macro parameters differently than 1.7 so 2.0 may not work as drop in replacement for your app which is designed to work with 1.7.
It would be interesting to hear comments about this change and if the test build works for you. All Velocity tests pass but real life use will most probably reveal bugs or design goofs that I overlooked.
PS. These changes are not limited to Velocity 2.0 so same logic could be applied to 1.7 to reduce memory consumption.