dev@glassfish.java.net

Performance tip of the day: config bean attribute access

From: Tom Mueller <Tom.Mueller_at_oracle.com>
Date: Wed, 10 Apr 2013 16:53:46 -0500

As I'm studying the GF code looking for performance improvements, I've
come across a common pattern that, if avoided broadly, could have a
positive impact on performance. The pattern is this:

Given some config bean, "bean" with a sub element called "some-value",
we have code that does:

     if (bean.getSomeValue() != null) {
         ValueType v = bean.getSomeValue();
         // do something with v
     }

Here, the assumption is that bean.getSomeValue() is cheap to call. But
given the reflection and transactions and numerous layers in the config
bean framework, this is not true. This can be more efficiently written as:

     ValueType v = bean.getSomeValue();
     if (v != null) {
         // do something with v
     }

Thanks.
Tom