As someone who is pretty focused on performance, I use Velocity to created pages from several smaller Velocity files, and also macros from other velocity templates, and I really don't have any performance issues (Not that performance can't always be improved). Without knowing more specifics of what you expect vs what you experience its hard to know what's going on.

How many files are parsed to form a single page?
Can you place a little timer around a merge call and time the method?
Is template caching on?

On Dec 25, 2008, at 17:36 , bluejoe wrote:

I use velocity-1.6-beta2, I'll try velocity-1.6.1. But I'm afraid my templates are too complex and include so many other templates.
Thanks a lot!

----- Original Message -----
From: "Will Glass-Husain" <[email protected]>
To: "Velocity Users List" <[email protected]>
Sent: Friday, December 26, 2008 1:17 AM
Subject: Re: question on Velocity parsing


Have you tried the new Velocity 1.6?  It has lots of performance
improvements.

WILL

On Wed, Dec 24, 2008 at 6:41 PM, bluejoe <[email protected]> wrote:

Thanks for your help, Mr. Nathan Bubna.

In my project I need define a new class extending from VelocityViewServlet so that createContext() and getVelocityEngine() methods are visible. See
belows:

public class MyServlet extends VelocityViewServlet
{
  public VelocityEngine getVelocityEngine()
  {
      return super.getVelocityEngine();
  }

  public Context createContext(HttpServletRequest arg0,
          HttpServletResponse arg1)
  {
      return super.createContext(arg0, arg1);
  }

  ...
}

Then I use MyServlet as a singleton tool to create contexts and help to render template pages. However, I can't use VelocityLayoutServlet directly, because the layout template maybe uses another layout. For solving this
problem, I write a method called layout() as follows:

public void layout(String templatePath, Context ctx, Writer writer)
          throws Exception
  {
      ctx.remove("layout");
      StringWriter sw = new StringWriter();

      render(templatePath, ctx, sw);

      String layout = (String) ctx.get("layout");
      if (layout != null)
      {
          ctx.put("body", sw.toString());
          layout(layout, ctx, writer);
      }
      else
      {
          writer.write(sw.toString());
      }
  }

I traced into the source codes and make sure that the cache works but the parse() method costs lots of time. I think it is caused by the complexity of
templates as following:

1. Templates use layout recursively;
2. Templates use many #parse directives to include other templates, such as
headers and footbars, and so on;

How is your idea?

Merry Chistmas!

bluejoe
2008-12-24

----- Original Message -----
From: "Nathan Bubna" <[email protected]>
To: "Velocity Users List" <[email protected]>
Sent: Thursday, December 25, 2008 1:39 AM
Subject: Re: question on Velocity parsing


First, you should not be using VelocityServlet, but instead use
VelocityViewServlet. As for parsing files more quickly, there is only
one parsing method available at this time.  You are welcome to try
serializing them, though i'm not aware of any effort to enable or aid
that process.  It may not be workable.

Just be sure you have caching on so that you only have to incur the
parsing time once and use the latest version of Velocity (1.6). Also,
try to simplify your templates if you still need more speed.  I'm
afraid that's about all that can be done right now.

On Tue, Dec 23, 2008 at 1:28 AM, bluejoe <[email protected]> wrote:
Hi, all,

Now I use Velocity and VelocityServlet to generate template files
(just like JSP pages) according to model template files, but I find the first-time loading cost much time. Can you tell me how to parse Velocity templates more quickly? Or is it ok to serailize parsed templates (It seems that they will be parsed as SimpleNodes) into files? I need your help.

  Thanks a lot!

bluejoe
2008-12-23

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]





---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to