[ 
https://issues.apache.org/jira/browse/VELOCITY-731?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13187966#comment-13187966
 ] 

Christopher Schultz commented on VELOCITY-731:
----------------------------------------------

Colin,

So your bean has a toString method that issues a JDBC call? That just seems 
like a bad idea in the first place.

There are other ways to check for the existence of a variable. For instance, 
instead of:

#if($objectWithExpensiveToStringMethod)

You can do this:

#if($objectWithExpensiveToStringMethod.class)

Every class has a getClass method (inherited from java.lang.Object) which will 
return null/false only if the object reference itself is null, so although it's 
less obvious what's going on (the .class on the end might raise some eyebrows), 
it gets the job done and doesn't hit your database.
                
> Velocity 1.6 performance is degraded by introduced toString() calls
> -------------------------------------------------------------------
>
>                 Key: VELOCITY-731
>                 URL: https://issues.apache.org/jira/browse/VELOCITY-731
>             Project: Velocity
>          Issue Type: Bug
>          Components: Engine
>    Affects Versions: 1.6, 1.6.1, 1.6.2
>         Environment: Apache Velocity 1.6.2
>            Reporter: Jörgen Rydenius
>             Fix For: 1.6.x, 1.7
>
>         Attachments: configurable_tostring_nullcheck_patch.txt
>
>
> As part of VELOCITY-531, r686428 introduced frequent calls to toString() just 
> to check if toString() != null. If toString() implementations are slightly 
> complex, and very frequently executed, these calls will degrade the site 
> performance. Are they at all necessary? What kind of object would use null as 
> a return value for toString()? Is it possible to remove these toString() 
> calls from the velocity code again?

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@velocity.apache.org
For additional commands, e-mail: dev-h...@velocity.apache.org

Reply via email to