camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mhillary <>
Subject RE: Bean Expression Performance
Date Mon, 25 Jun 2012 08:01:36 GMT
Hi Claus,


I had a go at fixing this myself yesterday. Would you accept a patch for


The change involves modifying the MethodCallExpression class to create the
BeanHolder in createExpression and provide this to the BeanExpression via a
new constructor. The BeanExpression then checks in the evaluate method if
the BeanHolder has been provided, if it hasn't then it will use the previous
logic to create the BeanHolder using the context from the exchange. This
means that when using method(.) the BeanHolder will get created up front,
but for bean(.) the existing behaviour is preserved. The reason for this is
that the BeanLanguage class doesn't seem to have access to the camel context
when it's creating the BeanExpression. Also without this change using the
method(.) syntax over the bean syntax is slower though I've not looked into


I wrote a small test case that iterates 1000 times on .setBody(method(new
TestBean(), "getValue")); where TestBean.getValue just returns "value". The
measured time by System.nanoTime drops from around 1200ms to 850ms.





From: Claus Ibsen-2 [via Camel]
Sent: 25 June 2012 08:01
To: mhillary
Subject: Re: Bean Expression Performance



Yeah we should optimize this. I have logged a JIRA

On Mon, Jun 25, 2012 at 12:13 AM, mhillary <[hidden email]> wrote: 

> Hi All, 
> I've been investigating some performance issues on a project that's using 
> Camel. As part of this I've noticed that bean expressions execute far more

> slowly than expected. For example the following line takes over 1ms in our

> tests whereas using a processor to do the same thing takes something like 
> 0.001ms; 
> setHeader("key", bean("java.util.UUID", "randomUUID")) 
> We measured this by setting a header before the line with the value of 
> System.nanoTime() and retrieving this value in the after the line had 
> executed. We also ran several 1000's of messages and got the same results 
> every time. This doesn't seem to be a problem with bean definitions. 
> I've dug into the code and think I've found the problem. When a 
> BeanProcessor is created a BeanHolder is also created and kept as a member

> variable. The BeanHolder contains a BeanInfo object that actually performs

> the introspection of the target bean. This means for a BeanProcessor the 
> target bean is only introspected once. However for a BeanExpression the 
> BeanHolder is created in the evaluate method and therefore a new BeanInfo 
> object is created for every message and the target bean gets introspected 
> for every message. 
> My question is; is there a reason for this or could the BeanExpression 
> implementation change to cache the BeanHolder object? 
> Thanks, 
> Mark Hillary 
> -- 
> View this message in context:
> Sent from the Camel - Users mailing list archive at 

Claus Ibsen 
Email: [hidden email] 
Twitter: davsclaus, fusenews 
Author of Camel in Action:


If you reply to this email, your message will be added to the discussion

To unsubscribe from Bean Expression Performance, click here
> .
ils%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> NAML 

View this message in context:
Sent from the Camel - Users mailing list archive at
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message