velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Shinobu Kawai <>
Subject Re: Performance Question.
Date Fri, 10 Dec 2004 12:14:46 GMT
Hi Andrew,

> Im using Velocity to render a relatively complex template (about 100
> substitutions).  Its working really nicely, but Im trying to optimise
> performance.
> Its taking about 50ms to render the template, but I was hoping I could
> improve that by turning on caching.

## Wow, you've got some impatient users.  I can usually wait up to 3 secs. ;)

>  Ideally Id like to load the templates
> from the classpath, but when that didn't work I used the File version,
> just to try and get some improvement.  I initted Velocity accordingly -
> Properties p = new Properties();
> p.setProperty("resource.loader","file");
> p.setProperty("file.resource.loader.class",
> "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
> p.setProperty("file.resource.loader.cache", "true");
> Velocity.init(p);
> Then I render my template using the following code :
> VelocityContext context = new VelocityContext();
> context.put("allRequests", allRequests);
> /* lets render a template */
> Velocity.mergeTemplate("xml/Template.xml", context, result );

Looks fine to me.

> Caching doesn't seem to make things any faster and I get the feeling Im
> doing something fundamental wrong.

How are you measuring it?  50ms isn't my idea of a good duration to
compare for performance tuning.  In some environments, java can't
measure less than 10ms.  It you rendered it 100 times, it should take
about 5 seconds w/o caching, right?  Have you tried that kind of

Ultimately, you should use a profiler to check where the bottleneck
is.  And don't forget to measure before and after making changes. 
Here's one of my favorite articles about optimization, written by
Martin Fowler:

> Apologies that this is a bit of a newbie question, but Ive read the
> support group etc. and I just cant get any optimisation.

Don't worry, we're all beginners at start.  Don't hesitate to ask, and
eventually we should end up with a rich FAQ.

Best regards,
-- Shinobu Kawai

Shinobu Kawai <>

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message