coordinationCost

Scores this Draft by the CoordinationCost a monotonicity-aware executor would pay.

Call plan first to minimise this cost before scoring.

See also

Samples

val src = OpId("source.docs")
val mapScore = OpId("map.score")
val filterThreshold = OpId("filter.above-threshold")
val embroider = OpId("embroider.rank")

// Programmer places embroider early (before the filter).
val unplanned: Draft<ByteArray> = Warp.shuttle(src)
    .map(mapScore)
    .embroider(embroider)
    .filter(filterThreshold)

// Build stats: 1 000 source docs, 50 pass the filter.
var stats = WarpStats.empty()
for (i in 1..1_000) stats = stats.piece(stats.observe(src, "doc_$i"))
for (i in 1..50) stats = stats.piece(stats.observe(filterThreshold, "doc_${i * 20}"))

// Unplanned: embroider before filter → full source cardinality.
val unplannedCost = unplanned.coordinationCost(stats)
check(unplannedCost.rounds == 1)
check(unplannedCost.coordinatedVolume >= 900L) { "should see ~1000 docs" }

// Planned: embroider deferred past filter → only ~50 docs reach consensus.
val planned = unplanned.plan(stats)
val plannedCost = planned.coordinationCost(stats)
check(plannedCost.rounds == 1)
check(plannedCost.coordinatedVolume < 100L) { "should see only ~50 docs after filter" }
check(plannedCost < unplannedCost)
check(unplanned.isEquivalentTo(planned)) { "plan must preserve equivalence" }