Introduction
Runtime monitoring is a critical safety mechanism for autonomous systems, such as unmanned aerial vehicles (UAVs), and decentralized financial protocols. These systems require real-time verification to ensure their behavior aligns with formal specifications. High-level, declarative stream-based languages like RTLola have emerged as a powerful tool for engineers to define these specifications. However, a significant performance gap exists between the high-level logic of stream equations and the low-level requirements of executable code. This paper introduces StreamIR, an intermediate representation (IR) designed to bridge this gap by enabling domain-specific optimizations that traditional compilers cannot perform.
The Problem: Safety vs. Performance
The execution of stream-based specifications typically faces a "safety vs. performance" trade-off. While declarative languages allow for safe and expressive logic—such as monitoring a drone's speed over a temporal window—executing these specifications efficiently is challenging.
Existing solutions generally fall into two categories, both with limitations:
- Interpreters: These are often too slow for high-frequency real-time monitoring.
- General-Purpose Compilers: While compilers like
rustcare excellent at low-level optimization, they lack the semantic understanding of stream logic. They cannot recognize opportunities to fuse redundant stream checks or optimize memory management for temporal lookups based on the relational properties of the data.
The StreamIR Framework
The authors propose a middle layer that understands both the declarative intent of the stream logic and the imperative requirements of the hardware. The workflow involves three primary stages:
1. Translation
Declarative RTLola specifications are converted into StreamIR. Unlike the source language, StreamIR utilizes imperative constructs such as if-then-else, iterate, and spawn, providing a more direct path to machine execution.
2. Domain-Specific Optimizations
Because StreamIR is specialized for streams, it can apply high-level rewrite rules. For instance, it can perform loop fusion across multiple data streams or move complex guards outside of iterations if the guards are independent of specific stream instances. A key breakthrough is the "Iterate-to-Assign" optimization: by proving that an iteration over multiple instances will only ever affect a single specific instance, the IR can replace a costly loop with a direct assignment.
3. Multi-Backend Support
StreamIR supports diverse execution environments through specialized backends:
- JIT Interpreter: A Just-In-Time compiler that handles the entire IR, offering significantly higher performance than expression-only JITs.
- Rust Formatter: Generates optimized Rust code tailored for embedded systems.
- Solidity Formatter: Compiles monitors directly into Ethereum smart contracts for on-chain verification.
Evaluation and Benchmarks
The framework was evaluated across three distinct domains to test its versatility and efficiency:
- Unmanned Aircraft (UAV): Benchmarks included Geofencing (spatial constraints) and Intruder Detection (monitoring proximity to other aircraft).
- Algorithmic Fairness: The researchers monitored the COMPAS dataset to detect bias in recidivism risk prediction algorithms.
- Smart Contracts: A suite of blockchain patterns (ERC20, Voting, Auctions) was used to measure transaction cost (gas) efficiency.
Key Results
The experimental results demonstrate substantial improvements over the state-of-the-art:
- Interpreter Performance: In the "Intruder" UAV specification involving 500 aircraft, the StreamIR-based interpreter achieved a 34x speedup over the previous RTLola interpreter, reducing execution time from approximately 930ms to 27ms.
- Compiler Superiority: StreamIR-optimized Rust code outperformed code generated by direct RTLola-to-Rust compilers. This confirms that high-level IR optimizations capture efficiencies that low-level compilers like
rustcmiss. - Blockchain Feasibility: In Solidity, the optimizations significantly reduced gas usage. Most notably, the "Iterate-to-Assign" optimization converted unbounded gas costs into bounded costs, making complex, real-time monitoring feasible on the Ethereum blockchain for the first time.
Conclusion and Future Work
StreamIR successfully demonstrates that a domain-specific intermediate representation can resolve the tension between high-level safety specifications and low-level performance requirements. By exploiting the relational properties of streams, the framework enables optimizations that are impossible for general-purpose compilers.
Future research directions include expanding support to other stream languages like TeSSLa or Striver, further automating memory footprint minimization for resource-constrained microcontrollers, and developing backends for hardware description languages (VHDL/Verilog) to target FPGA-based monitoring systems.
Summary updated