coordinationCost
Scores this Draft by the CoordinationCost a monotonicity-aware executor would pay.
CoordinationCost.rounds = count of coordinated nodes (0 for fully-monotone drafts; each DraftStage.Embroider or DraftStage.BatchedEmbroider contributes 1).
CoordinationCost.coupling = maximum batch size across all coordinated nodes (0 when fully monotone, 1 for a lone DraftStage.Embroider,
opIds.sizefor a batched node).CoordinationCost.coordinatedVolume = sum of volume estimates across all coordinated nodes. Each estimate is derived by walking the predecessor graph and applying per-filter selectivities from stats. Unknown filters (zero cardinality in stats) contribute no reduction — a conservative choice.
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" }Content copied to clipboard