Gossamer Forum
Home : Products : Gossamer Links : Discussions :

questions regarding template performance

Quote Reply
questions regarding template performance
Hi GT,

I have a question about when and where to run custom coding(plugin or template). The template codes allows for us to do something like:
<%Links::MyCustomCodes::mysubroutine(param1=>something,param2=>something)%> I love this and use it all the time, but lately since 3.x upgrades have wondered if this results in significant performance issues.

I have certainly identified performance problems with MY code between 2.x and 3.x, but this is more of a general performance question which is... Is there a performance issue when calling custom code through a template.

For example, it's possible to run the logic for entire program by using a template as a controller like this:
<%if somevalue%>
<%Links:myscript:runthisroutine()%>
<%include thistemplate.html%>
<%elsif someothervalue%>
<%Links:myscript:runthisotherroutine()%>
<%include thisothertemplate.html%>
<%else%>
<%Links:myscript:defaultroutine()%>
<%include defaulttemplate.html%>
<%endif%>

Is that as fast as running those if statements inside of a plugin perl script before processing the template?

thank you for any insight you can provide.

peace.
Quote Reply
Re: [klangan] questions regarding template performance In reply to
It's definitely going to be slower doing things in the templates like that, but with something as short as that, it shouldn't be a noticeable difference.

Adrian
Quote Reply
Re: [brewt] questions regarding template performance In reply to
Thanks brewt,

That helps. Just a follow up. If I'm running something like this in link.html

<%Links::mycode::myfunction()%> - as that gets iterated over at least 25 times under default settings - do I assume that this represents a significant decrease in performance.

thank you for your insight.

peace.
Quote Reply
Re: [klangan] questions regarding template performance In reply to
Depending on what your function does and the speed of it, yes, it could slow things down.

Adrian
Quote Reply
Re: [brewt] questions regarding template performance In reply to
Hi Brewt,

So calling an external function in and of itself doesn't decrease performance?
(I realize that what I do in the code can make a huge difference)

ie is there a performance difference between the following:

In the code:
while (my $link = $sth->fetchrow_hashref) {
$link->{myDescription} = Links::myscript::mycode($link->{Description});
}

vs.

In the template:
<%loop links_loop%>
...
<%Links::myscript::mycode($Description)%>
...
<%endloop%>


Thanks, I promise this will be my last question about this.

peace.
Quote Reply
Re: [klangan] questions regarding template performance In reply to
As I mentioned before, there's a bit of overhead of running things in the templates, but if it's only a small loop being looped a small number of times (like less than 50?), then it should be okay. You can always do it both ways and see how much of a difference it makes.

Adrian