Runtime invariants
Some computations are runtime invariant. They can be computed on startup and remain constant throughout the execution of the program.
composite Main {
param
expression<int32> $x : (int32)getSubmissionTimeValue("x", "10");
graph
stream<int32 dummy> Beat = Beacon() {}
stream<Beat> Filtered = Filter(Beat) {
param filter: $x < dummy;
}
}The compiler substitutes all occurrences of $x with the actual
value:composite Main {
param
expression<int32> $x : (int32)getSubmissionTimeValue("x", "10");
graph
stream<int32 dummy> Beat = Beacon() {}
stream<Beat> Filtered = Filter(Beat) {
param filter: (int32)getSubmissionTimeValue("x", "10") < dummy;
}
}Each time the Filter operator receives a tuple, it evaluates the filter
expression. It invokes
(int32)getSubmissionTimeValue for each tuple received.
Since (int32)getSubmissionTimeValue returns a runtime invariant result, you
can invoke it once in a logic clause and capture its value in a local static
variable. This technique is much more efficient since
(int32)getSubmissionTimeValue is only invoked once instead of once per
tuple:composite Main {
param
expression<int32> $x : (int32)getSubmissionTimeValue("x", "10");
graph
stream<int32 dummy> Beat = Beacon() {}
stream<Beat> Filtered = Filter(Beat) {
logic
state int32 x = $x;
param
filter: x < dummy;
}
}