Apama 10.15.0 | Developing Apama Applications | Developing Apama Applications in EPL | Working with Streams and Stream Queries | Using dynamic expressions in stream queries | When to avoid dynamic expressions in stream queries
 
When to avoid dynamic expressions in stream queries
Where possible, use static expressions in preference to dynamic expressions. This allows the compiler to optimize the query to improve performance. For example, consider the following query:
stream<float> vwaps := from t in all ticks
   within vwapPeriod
   select wavg(t.price,t.volume);
When vwapPeriod is a monitor global variable whose value does not change, then it is preferable to copy the value to a local variable first. For example:
float period := vwapPeriod;
stream<float> vwaps := from t in all ticks
   within period
   select wavg(t.price,t.volume);
Similarly, if it is known that a given action call always returns the same value, then it is preferable to copy the result to a local variable and use this in place of the action call. For example:
float period := getVwapPeriod(symbol);
stream<float> vwaps := from t in all ticks
   within period
   select wavg(t.price,t.volume);