Frage

I'm using StringTemplate 4 to internally generate web pages in an Android application.

The templates used in my application server (for web access) are also used to generate pages internally in the Android application, this combined with a json data store mechanism allows the Android application to even run offline in most cases, and using exactly the same application logic and templates from the server.

The problem I'm having now is performance. A typical server request is processed in approximately 200 ms: request analysis, verification, process, ST4 load and html page generation. This is fine for me, I have some performance improvements pending, but I think it's quite good for now.

However in the Android application the ST4 load takes 1-1,5 seconds. The template structure may have 2 or 3 levels, and the templates have several renderers. I've done some tests like creating a one level template (stg without imports) but the performance is not improved, so I think has something to do with template parsing and renderer loading.

Is there any way to improve ST4 load and parsing? Is there any way to store and load a CompiledST object or something similar?

I think the ST4 concept is very good, however if a ST does not change, why loading and parsing the template, and related templates, every time? I know there is a caching mechanism, however I'm loading different stg for each request so this does not save time in the first loads and caching all stg may eat the device memory.

War es hilfreich?

Lösung

The reference implementation of StringTemplate does not currently support serializing/deserializing precompiled templates. The C# port of StringTemplate 4 does support this, and the feature is controlled via the TemplateGroup.EnableCache flag.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top