Discussion: template EEL lazy evaluation

Hi,

I would like to discuss our current EEL lazy evaluation behavior in templates.

If you create a Fusion Template object and assign a variable with an EEL expression, that expression is put in a Proxy object and lazily evaluated when accessed in the template. The intention was to avoid overhead for not used expressions that are assigned. There is a drawback though, the expression is execute twice if the variable is used twice in the template.

You can easily see the effect if you assign an expression with a math random call to a template:

random = ${Math.random()}

And output the variable twice in the template, you will see two different random values.

Now that could be a desired (side) effect but I rather see it as a bug. First it hurts performance if we execute expressions multiple times, second it’s IMHO unexpected in the template that outputting the same variable can yield different results.

As a result I would be in favour of changing this behaviour and (runtime) cache the result of such an expression in the proxy object when it is first executed.

For reference, this post brought me to the discussion: [SOLVED] Template variable has multiple values

3 Likes

Hey Christian,

caching this in the proxy object definitely makes sense for me :slight_smile:

All the best,
Sebastian

That makes sense and i really like the idea.

Offcourse this changes the behavior but i cannot imagine a situation where i would consider the old behavior beeing better or more correct.

+1 for improving/fixing this, have previously brought it up and spend a little time trying to solve it but turned out more difficult than anticipated unfortunately so dropped it again.

I’ve been using f:alias as a workaround for this problem.