Package liqp

Interface RenderTransformer


public interface RenderTransformer

A RenderTransformer handles the conversion of objects to be returned by Template.renderToObject() etc.

Implementations may optimize how objects are actually appended/serialized, and when exceptions are thrown in the case that the final result would be too long.

The default implementation, RenderTransformerDefaultImpl, simply appends strings to a StringBuilder. While this will work in many cases, there is a chance that large strings are created temporarily on the heap, increasing the chance of an out-of-memory situation, and a generally high allocation activity (spikes in the memory allocation graph).

For example, the following liquid template results in 10012 StringBuilder.toString() conversions:

{% for l in (1..10)%}{% for k in (1..1000) %}
   {% for i in (1..1000) %}Hello! {{ i }} world
{% endfor %}{% endfor %}{% endfor %}
With a custom implementation such as stringhold's StringHolderReaderTransformer, the number of actual `toString` conversions can be as low as 1, and — depending on specific implementation tricks (such as reusing instances of identical partial sequences) — a significantly lower memory footprint can be observed (in this case, with stringhold, 7x less usage). If the data is to be written to a Writer (instead of serializing to a complete string), an even lower memory footprint can be achieved (35x less usage was observed).

Author:
Christian Kohlschütter
See Also: