Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Optimizing code in web applications

Prince VJun 2 2024 — edited Jun 3 2024

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 ?

Comments
Post Details
Added on Jun 2 2024
1 comment
100 views