Skip to content

v0.4.3

Choose a tag to compare

@lilith lilith released this 29 Mar 02:02
· 57 commits to main since this release

What's New

almost-enough: DebouncedTimeout

A deadline wrapper that learns how fast check() is called and skips most Instant::now() reads. Useful when the caller adds a deadline but the library controls check frequency — neither side can optimize the other's hot path.

How it works: Starts by reading the clock every call, then adapts skip_mod so clock reads happen roughly every 100μs (configurable). Adapts immediately when calls slow down (safety), gradually when they speed up (stability).

Performance:

Workload WithTimeout DebouncedTimeout
Tight loop (no work) 59M checks/s 648M checks/s (11x)
Jittery (~100ns avg) 29M checks/s 62M checks/s (2.1x)
Codec (4KB chunks) 17.1 GiB/s 18.1 GiB/s (equivalent)

API:

use almost_enough::{Stopper, DebouncedTimeoutExt};
use std::time::Duration;

let stop = Stopper::new()
    .with_debounced_timeout(Duration::from_secs(30));
// Pass to any library accepting impl Stop

Also available: with_debounced_deadline(), with_target_interval(), tighten(), tighten_deadline().

Maximum deadline overshoot equals the target interval (default 100μs).