When optimizing java code in web applications, should we focus more on reducing memory utilization or reducing no of lines of computation.
In the following pseudocode item.getPricingInfo() is called 3 times
int getOrderTotal()
{
int orderTotal = 0;
Order order = cart.getCurrentOrder()
for(OrderItem item: order.getItems())
{
orderTotal += (item.getPricingInfo().getItemSalePrice() + item.getPricingInfo().getItemTaxAmount()) - item.getPricingInfo().getItemDiscount();
}
return orderTotal;
}
In the following pseudocode item.getPricingInfo() is called only once. But i have declared a reference
ItemPricingInfo itemPricingInfo = item.getPricingInfo();, which will add a new entry in stack
int getOrderTotal()
{
int orderTotal = 0;
Order order = cart.getCurrentOrder()
for(OrderItem item: order.getItems())
{
ItemPricingInfo itemPricingInfo = item.getPricingInfo();
orderTotal += (itemPricingInfo.getItemSalePrice() + itemPricingInfo.getItemTaxAmount()) - itemPricingInfo.getItemDiscount();
}
return orderTotal;
}
Assuming the above code is deployed in an environment which does not support scaling of computing and memory resources, which approach is better for optimizing web applications ?