Expand description
Compression level adaptation for a sender whose bottleneck moves.
The caller compresses in windows, records each frame’s work in
CompressStats, and names what limited the window, like C zstd’s
--adapt. A blocked output or idle input asks for ratio. Queued input
with free output asks for compression speed. The level walks one step at
a time toward the goal, crossing small dips, and reverts a step that
clearly hurts. Neither ratio nor speed is monotonic in the level for every
input, so a finished walk settles on the best recently measured level.
Speed is input bytes per second spent compressing. End-to-end throughput varies too much between short windows to rank levels.
use core::time::Duration;
use zrip::adaptive::{AdaptiveLevel, Bottleneck, CompressStats};
let mut adaptive = AdaptiveLevel::new(-7..=4, -1);
let mut stats = CompressStats::default();
// After each frame: input bytes, frame bytes, and time spent compressing.
stats.record(64 * 1024, 20 * 1024, Duration::from_micros(300));
// After each window of at least `MIN_WINDOW_BYTES` input:
let level = adaptive.update(stats, Some(Bottleneck::Output));
assert_eq!(level, 1);Structs§
- Adaptive
Level - Hill climb over the distinct zrip levels of one range.
- Compress
Stats - Compression work done in one window.
Enums§
- Bottleneck
- What limited the sender during one window.
Constants§
- MIN_
WINDOW_ BYTES - Input a window should cover at least. Smaller windows rank levels by measurement noise.