Runtime monitors that are speciﬁed in a stream-based monitoring language tend to be easier to understand, maintain, and reuse than those written in a standard programming language. Because of their formal semantics, such speciﬁcation languages are also a natural choice for safety-critical applications. Unlike for standard programming languages, there is, however, so far very little support for automatic code optimization. In this paper, we present the ﬁrst collection of code transformations for the stream-based monitoring language RTLola. We show that classic compiler optimizations, such as Sparse Conditional Constant Propagation and Common Subexpression Elimination, can be adapted to monitoring speciﬁcations. We also develop new transformations — Pacing Type Reﬁnement and Filter Reﬁnement — which exploit the speciﬁc modular structure of RTLola as well as the implementation freedom aﬀorded by a declarative speciﬁcation language. We demonstrate the signiﬁcant impact of the code transformations on benchmarks from the monitoring of unmanned aircraft systems (UAS).
20th International Conference on Runtime Verification