Consider the order of terms in compound expressions

As a performance best practice, Guidewire recommends that you carefully consider the order of comparisons in compound expressions that use the and and or operators. Runtime evaluation of compound expressions that use and proceed from left to right until a condition fails. Runtime evaluation of compound expressions that use or proceed from left to right until a condition succeeds. The order in which you place individual conditions can improve or degrade evaluation performance of compound expressions.

With and expressions, place terms likely to fail earlier

Whenever you use the and operator, place the condition that is most likely to fail or the least performance intensive earliest in the compound expression. Use the following formula to help you determine which condition to place first, based on the condition with the lowest value.

(100 - failurePercentage) * (performanceCost)

For example, you have a condition that you expect to fail 99% of the time, with an estimated performance cost of 10,000 per evaluation. You have another condition that you expect to fail only 1% of the time, with an estimated performance cost of 100 per evaluation. According to the formula, place the second condition earliest because it has the lowest score.

(100 - 99) * 10,000 = 10,000
(100 - 1) * 100 = 9,999

You rarely have accurate figures for the failure percentages or performance costs of specific condition. Use the formula to develop an educated guess about which condition to place earliest. In general, give preference to less performance intensive condition. If the performance costs are roughly equal, give preference to condition with a higher percentage of likely failures.

With or expressions, place terms likely to pass earlier

When you use the or operator, place the condition that is most likely to succeed earliest in compound expressions.