On Tue, Apr 17, 2001 at 06:29:56AM -0400, Geir Magnusson Jr. wrote:
> Jason van Zyl wrote:
> > I will clean up what I have and try to push it into CVS in
> > the next couple of days. What I have creates a Template class
> > in memory, something that could be placed in the cache.
> > 
> > The idea is to try and get rid of all reflection in an attempt
> > to make the rendering go as fast as possible. What I am assuming,
> > in order for compilation to be of any use, is that the type
> > represented by a reference in VTL is constant. This is not
> > what Velocity assumes right now.
> 
> I don't think that assumption has to be there.  That 'polymorphism', in
> that 
> 
> $object.foo
> 
> can be rendered from a Map or *any* class that looks like
> 
> class MyClass
> {  
>    public String getFoo();
>    public String get( String );
> }
> 
> w/o inheritance worries is a really great feature.
> 
> 

Hmmm.... since we're talking about an in-memory compiler, theoretically we _could_ 
change the class' constants table on the fly in response to different types, adding 
new types as they come in on the Context and simply index into different type 
declarations for the method call.  Back in the real world, I agree with Jason... if 
you use different classes arbitrarily (e.g. Moose v. Sheep with no common base class), 
you can't expect to not suffer the reflection penalty.

Perhaps compiling an entire template (the all-or-nothing) approach isn't the right way 
to think of this:  we could do some heuristic monitoring at runtime and 'optimize' 
nodes that warrant it on the fly.  Whereas in our discussion we create an in-memory 
class derived from Template that implements merge, we instead create an in-memory 
class derived from Node that implements render().  In a simple template, where types 
are deemed to be consistent, the root node may be optimized.  (This would, in effect, 
be the same as compiling the entire template).  In other scenarios, some nodes might 
be compiled while others still use reflection.  In the event of an invocation error in 
a compiled node, we dispatch the context back to the compiled node's AST peer.

voila! Velocity Hotspot!

-art

Reply via email to