cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Is there any Performance impact of Dynamic Value?

Former Member
0 Kudos
425

I want to add some behaviour to some objects via dynamic attributes. I am also concerned if those attributes are frequently used, then, would calling the attribute handler every time impact the performance? For example, say I want to add an attribute 'isSpecial' to Products which will be calculated on the fly based on some other attributes. If this is to be called every time I add the product to cart, should I move the logic into services (and scatter it at many places) to save over performance (for a heavy object like a cart)?

Should i call the attribute handler like:

 public class ProductXXXAttributeHandler implements DynamicAttributeHandler<Boolean, ProductModel> {
 
     @Override
     public Boolean get(ProductModel product) {
         return product.getExclusiveTill()!=null?product.getExclusiveTill().after(new Date()):false;
     }

or should I move this to the Add to cart Strategy, like:

 public class XXXCommerceAddToCartStrategy extends DefaultCommerceAddToCartStrategy {
 
  public CommerceCartModification addToCart(CommerceCartParameter parameter) throws CommerceCartModificationException {
 ...
 ProductModel product = paramter.getProduct();
 
 isExclusive = product.getExclusiveTill()!=null?product.getExclusiveTill().after(new Date()):false;
 
 ....
 }


WHICH ONE WILL BE CONSIDERABLY FASTER?

Accepted Solutions (1)

Accepted Solutions (1)

arvind-kumar_avinash
Active Contributor
0 Kudos

You should keep in mind that dynamic attributes are not cached. So, if there are too frequent reads, the performance will be impacted.

Former Member
0 Kudos

I have added some more details in the question. Could you please check and reply?

arvind-kumar_avinash
Active Contributor
0 Kudos

If I have to use the logic product.getExclusiveTill()!=null?product.getExclusiveTill().after(new Date()):false; just while adding to cnd not anywhere else, I would keep it in the Strategy; otherwise (to make this calculated value of the product attribute reusable at multiple places e.g. for personalization etc.), I would make it dynamic.

Answers (0)