[stringtemplate-interest] Unscientific benchmarks
VAUCHER Laurent
VAUCHER at fermat.fr
Tue Oct 18 01:10:10 PDT 2005
Well,
as you may recall, I was very satisfied by StringTemplate's design,
but a bit less by its raw performance. Making heavy use of reflection,
that was not a big surprise. So I tried two approaches to boost the
rendering speed.
First, I tried a crude implementation of 'reflection caching', having
seen the subject in Terence's to-do-list.
Then, I tried replacing reflection by classes generated on the fly
with a bytecode library (ASM).
On a totally unsignificant and unscientific data set (1000 rows from a
database with around twenty fields, plus a structured display
description) here are the results I got (JDBC fetch excluded) :
Normal StringTemplate 8.9 s = 100%
Reflection caching 6.4 s = 72%
ASM access generation 6.3 s = 71%
There are a dozen templates involved and around 200.000 attribute
accesses. The ASM version generates 26 classes in 46 ms. And the DB rows
are presented as HashMap: it means that getting attributes is the same
for those objects in all versions (no reflection, no bytecode
generation).
What can we conclude? Not very much, because the testing is not very
precise, but at least: reflection caching is very simple and seems well
worth. ASM is quite a bit more complicated but "make no mistake" [(c)
G.W.Bush] it can give a substantial boost. In this test, I just replaced
the simple access part with generated classes. I have plans to ASMify
the whole StringTemplate object or at least it's evaluation part...
Laurent.
More information about the stringtemplate-interest
mailing list