pub fn batch_decision(
policy: &BatchPolicy,
exec: &Exec<'_>,
query: &BatchQuery,
) -> BatchDecisionExpand description
Decide the route for one batch on the budget and the dispatch costs of exec
under policy.
Forced strategies are clamped (lanes <= min(items, budget),
lanes * item_threads <= budget) but never fall back. Auto narrows the
budget first (see the module docs) and uses the original budget only for the
forced strategies.
Whether a route can run the returned decision is the route’s own
preflight: a decision with both lanes and item threads is honoured or
refused before any output write, never partially applied (see
BatchDecision’s route contract).
§Examples
use std::num::NonZeroUsize;
use tcontract_exec::batch::{batch_decision, BatchPolicy, BatchQuery, BatchStrategy};
use tcontract_exec::{Exec, Pool};
let sp = threadteam::Pool::builder().threads(4).build().unwrap();
let pool = Pool::borrow(&sp);
let exec = Exec::new(&pool, 4).unwrap();
let query = BatchQuery::new(2, 1024.0);
let split = BatchPolicy::new(BatchStrategy::Split {
lanes: NonZeroUsize::new(8).unwrap(),
});
let d = batch_decision(&split, &exec, &query);
// Clamped to the items and the budget.
assert_eq!(d.lanes * d.item_threads, exec.budget());
assert_eq!(d.lanes, 2.min(exec.budget()));