//! Adaptive sub-batch sizing: [`next_batch_size`] adapts the tracer's sub-batch sample
//! count toward [`TARGET_SUBBATCH`], given how long the previous sub-batch actually took.
use Duration;
/// The wall-clock duration [`next_batch_size`] adapts sub-batch sizes toward. Bounds
/// both cancellation latency (the tracer only checks its cancel flag between
/// sub-batches) and scheduling granularity, on hardware ranging from an A100 on a LAN
/// to a 2060 over hotel wifi, without hardcoding a sample count wrong for either end.
pub const TARGET_SUBBATCH: Duration = from_millis;
/// Absolute ceiling on a single sub-batch, regardless of how favorable the timing that
/// fed [`next_batch_size`] looked. Defense in depth: the relative 4x-per-step clamp
/// below only bounds growth relative to the PREVIOUS result, so nothing stops many
/// steps compounding if measurements keep landing well under [`TARGET_SUBBATCH`] (e.g.
/// dispatch overhead dominating a small sample count on faster hardware). Comfortably
/// below `crate::validate::MAX_SAMPLES_PER_REQUEST` so it can bind before a single
/// sub-batch swallows a whole request's remaining range.
pub const MAX_SUBBATCH: u32 = 2048;
/// Adapts the next sub-batch's sample count toward [`TARGET_SUBBATCH`], given how long
/// `prev` samples actually took to trace. Grows (up to 4x, never past [`MAX_SUBBATCH`])
/// when the previous batch finished well under budget, shrinks toward 1 when it ran
/// over, and never returns 0 -- converges on a sub-batch size that fits the worker's
/// own actual throughput rather than a single hardcoded sample count.
pub