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

Claus Ibsen commented on CAMEL-19098:
-------------------------------------

Thanks for reporting, I am working on a fix. 

So for string literals then you need to pass them in as quotes to have it fast. 
If you use merhod=myMethod(slow) then Camel uses its parameter type matching 
(this was implemented first) and therefore assume slow is a java class name, 
such as String, int, boolean etc.

But with the fix, then only 1 is slow, and all the 3 others are fast

> Possible performance issue invoking a bean method with a string parameter
> -------------------------------------------------------------------------
>
>                 Key: CAMEL-19098
>                 URL: https://issues.apache.org/jira/browse/CAMEL-19098
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-bean
>    Affects Versions: 3.20.2
>            Reporter: Moshe Elisha
>            Assignee: Claus Ibsen
>            Priority: Major
>             Fix For: 3.18.6, 3.20.3, 3.21.0, 4.0-M2, 4.0
>
>
> Hi,
>  
> As discussed in the Camel users email thread - 
> [https://lists.apache.org/thread/3whp1726zttcckh20tdn0j9wj9vt6tgd]
>  
> I have noticed that when invoking a bean method with a string parameter, it 
> works but a very special handling is needed to avoid a performance hit. 
> Example code below.
> When the parameter is not single quoted or double quoted - Camel tries to 
> resolve the value and in the process tries to load a class by that name which 
> is a very expensive process. This behavior is expected IMO.
> When the parameter is single quoted or double quoted - Camel still tries to 
> resolve the value as a class name. IMO this is not behaving properly.
> This issue happens because 
> "StringQuoteHelper.splitSafeQuote(methodParameters, ',', true);" invoked in 
> "MethodInfo.ParameterExpression#evaluate" removes the single/double quotes.
> Inside "MethodInfo.evaluateParameterValue" the 
> "BeanHelper.isValidParameterValue(exp)" is invoked and returns false and 
> therefor "BeanHelper.isAssignableToExpectedType" > ... > 
> "DefaultClassResolver.loadClass(String name, ClassLoader loader)" is invoked 
> every time the bean method is invoked.
> The current workaround I found is to add both types of quotes. With this 
> workaround, "MethodInfo.ParameterExpression#evaluate" removes the outer set 
> of quotes but keeps the inner one and "BeanHelper.isValidParameterValue(exp)" 
> returns true.
>  
> {{public class MyRouteBuilder extends RouteBuilder {}}
> {{    @Override}}
> {{    public void configure() throws Exception {}}
> {{        from("timer:foo?period=2000")}}
> {{            .to("bean:myBean?method=myMethod(slow)")}}
> {{            .to("bean:myBean?method=myMethod('alsoSlow1')")}}
> {{            .to("bean:myBean?method=myMethod(\"alsoSlow2\")")}}
> {{            .to("bean:myBean?method=myMethod(\"'fast'\")");}}
> {{    }}}
> {{}}}
> {{public class MyBean {}}
> {{    public void myMethod(String str) {}}
> {{        System.out.println("str = " + str);}}
> {{    }}}
> {{}}}
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to