Interface ConditionCostModel


public interface ConditionCostModel
Estimates the relative runtime cost of evaluating rule engine conditions.

Costs are relative values where lower numbers indicate cheaper operations. The absolute values don't matter - only their relative ordering affects optimization decisions.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    cost(Condition condition)
    Estimates the relative cost of evaluating a condition.
    Creates a default cost model that derives costs from function definitions.
    createDefault(int nestedMultiplier)
    Creates a default cost model with a custom multiplier for nested functions.
    Create a cost model that assigns equal cost (1) to all conditions.
  • Method Details

    • createDefault

      static ConditionCostModel createDefault()
      Creates a default cost model that derives costs from function definitions.

      This model uses LibraryFunction.getFunctionDefinition()'s cost and applies a multiplier of 2 for nested function arguments.

      Returns:
      a new default cost model
    • createUniform

      static ConditionCostModel createUniform()
      Create a cost model that assigns equal cost (1) to all conditions.

      Use this when cost-based ordering should be disabled, allowing other factors (CFG structure, cone size, dependencies) to determine condition order exclusively.

      Returns:
      uniform cost model
    • createDefault

      static ConditionCostModel createDefault(int nestedMultiplier)
      Creates a default cost model with a custom multiplier for nested functions.

      The cost of a condition is computed as:

       cost = baseCost + sum(nestedFunctionCost * nestedMultiplier)
       

      For example, with a multiplier of 2, the condition isSet(parseUrl(endpoint)) would have cost: 10 + (200 * 2) = 410, reflecting that the expensive parseUrl must be evaluated before the cheap isSet can run.

      Parameters:
      nestedMultiplier - multiplier applied to nested function costs (typically 2-3)
      Returns:
      a new cost model with the specified multiplier
    • cost

      int cost(Condition condition)
      Estimates the relative cost of evaluating a condition.

      Lower values indicate cheaper operations that should be evaluated earlier when BDD structure permits.

      Parameters:
      condition - the condition to evaluate
      Returns:
      relative cost estimate (lower = cheaper)