High Roller
This no_std crate includes tools for tracking rolling-window
statistics in latency-sensitive systems. The motivating case was
reporting downsampled performance telemetry in embedded applications,
but it's hopefully useful for other domains as well.
Contents
This crate contains three members:
- Rolling Max: tracks the greatest value in a fixed-size window.
- Rolling Sum: tracks the sum of entries in a fixed-size window.
- Decimal32: a 32-bit fixed-precision decimal type. Pairs with
RollingSumwhen float precision is needed. Native floating point types are incompatible withRollingSum's overflow recovery mechanism.
Design
This crate has the following design motivations:
- Algorithmic optimality: Max and overflow-resilient Sum expose asymptotically optimal operations.
- Performance orientation: no_std, no heap allocs, and a performance-aware approach to implementation. Demonstrated performance improvement contributions are also very welcome.
- Code simplicity: this crate has more lines of docs than actual code. When feature availability and simplicity collide, the latter is chosen.
Example
The example below shows how high_roller could be used to track
and publish request latency telemetry in an application with
scheduled ticks and structured I/O patterns.
The example expects a request every 1/3 ticks, publishes telemetry every 100 ticks, and tracks a window of 1000 ticks.
use Reverse;
use D5;
use RollingMax;
use RollingSum;
/// Track a rolling window of this many ticks.
const WINDOW: usize = 1000;
/// Expect a request every 1 / 3 ticks.
const EXPECTED_INTERVAL: u32 = 3;
/// Emits telemetry on the rolling window of 1000 ticks.
/// Emitted every 100 ticks.
let mut io = new;
let mut telemetry = default;
while io.tick
/// An accumulator for dynamic system telemetry.
/// A dummy I/O layer.
;
Roadmap
High Roller is usable as-is, but here's the plan for upcoming improvements.
- Performance profiling and
cargo bench.- Compare naive and optimized rolling sum.
- Compare naive and optimized rolling max.
- Compare ringbuffer and VecDeque rolling max.
- Performance profile of Decimal32 operations. How do instructions compare to f32?
- Experiment with size optimizations in RollingMax.
- BitVec rolling sum for accumulating a window of boolean counters.
- DoubleBitVec and DBV rolling sum for accumulating the range 0..4.
See CHANGELOG.md for release notes.
License
Licensed under either of the following at your option:
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
Unless explicitly stated otherwise, any contribution to this crate shall be dual licensed as above without any additional terms or conditions.