On 3/13/02 2:26 AM, "Christian Trutz" <[EMAIL PROTECTED]> wrote:

> Hello Velocity community,
> 
> I am new to this mailing list, my name is Christian Trutz and I am a graduate
> student (mathematics) at University Bonn in Germany. Velocity is for me a
> cool and useful tool and I want to contribute a little.

Great

> 
> In the actual CVS tree there is a incomplete
> org.apache.velocity.runtime.compile.Compiler class. This class wants to
> compile a template via BCEL. I think it's better to generate first a java
> file and then compile this with an usual compiler. What I mean:
> 
> 
> Velocity file:
> -----------
> Hello $foo
> -----------
> 
> after "compilation" you get something like this:
> 
> ----------------------------------------------------------
> public class CompiledTemplate {
> 
>   public void merge( Context context, Writer writer) {
>          
>               writer.write("Hello ");
>               writer.write( context.get( "foo" ) );
>   }
> }
> --------------------------------------------------------
> 
> Is this a good idea???

Not sure - I mean, JSP does this :)

> 
> Is anybody working on a Velocity template compiler?


I guess the question is - is there any point to doing this? :)  It's not
clear to me what kind of real performance improvements can be realized by
compiling, because once the template is intepreted, it's bytecode, right?

I think the motivation for starting a compiler was when we believed that JSP
was incredibly fast and Velocity was slow.  Since thing, we have proved to
ourselves many times that Velocity is comparable in performance to JSP,
which is of course, compiled from generated Java code.

I would be interested in understanding if there really is potential for
improvement doing this, or if we are just making things more complex with no
real benefit.

In the case above, you took what is now basically

  for(int j=0; j<numchildren; j++)
  {
    getChild(j).render();
  }

And unwound the loop into the two writes

I am sure there is performance improvement there and it could significant in
such a trivial case (or other optimal situations), but the question is how
that improvement scales for real-world templates.


> 
> The AST (see JJTree) implemets the visitor pattern and any AST node has a
> render method ... why? Is rendering with a visitor not so good?

We use the tree for different things, and the render() approach works quite
well for us.  Visitor is good, and we do use it for things, sometimes...

Geir

-- 
Geir Magnusson Jr.                                     [EMAIL PROTECTED]
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to