We are using Apache Velocity for website templates and some of them are getting complex. Have you noticed any performance issues with certain Velocity features? And how did you get around them?
VelocityContext(Context innerContext) Chaining constructor, used when you want to wrap a context in another. VelocityContext(Map<String,Object> context) Creates a new instance with the provided storage (and no inner context).
Velocity is a Java-based templating engine. It's an open source web framework designed to be used as a view component in the MVC architecture, and it provides an alternative to some existing technologies such as JSP. Velocity can be used to generate XML files, SQL, PostScript and most other text-based formats.
Apache Velocity first released in April 2001, is a Java-based template engine that provides a template language to reference objects defined in Java code. It aims to ensure clean separation between the presentation tier and business tiers in a Web application (the model–view–controller design pattern).
The Apache Velocity Engine is a free open-source templating engine. Velocity permits you to use a simple yet powerful template language to reference objects defined in Java code.
First of all use the latest velocity library(1.7 or 1.6.4). Version 1.5 contains some serious performance issues!
Also here is the list of parameters that you must tweak on production environment:
The most important feature people often overlook is resource loader caching (off by default) which boosts performance quite a bit (file.resource.loader.cache
).
#parse
directive also has noticeable performance impact, try to use it only to avoid code duplication, not to just split templates into logical parts.
If your templates becoming quite complex in terms of logic maybe it would be possible to shift that logic to a controller and provide a template with ready to render data structure.
I didn't notice any performance drops from Velocity, when I was testing Velocity speed before switching from JSP they were constantly 50% faster on any template I threw at them. Currently we generate sites with thousands of pages rendered from Velocity templates and it is lightning fast, very satisfied with performance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With