From abb19b502795c28538eb50c8ee6bf02750fc46e6 Mon Sep 17 00:00:00 2001 From: Milind Srivastava Date: Tue, 21 Jul 2026 20:46:16 -0400 Subject: [PATCH] refactor(planner): hoist subpopulation_count placeholder into a shared constant --- asap-planner-rs/src/optimizer/constants.rs | 6 ++++++ asap-planner-rs/src/optimizer/cost_model.rs | 10 +++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/asap-planner-rs/src/optimizer/constants.rs b/asap-planner-rs/src/optimizer/constants.rs index 21c71f84..cd4bd0c0 100644 --- a/asap-planner-rs/src/optimizer/constants.rs +++ b/asap-planner-rs/src/optimizer/constants.rs @@ -33,3 +33,9 @@ pub const INGEST_MEM_WEIGHT: f64 = 1e-9; pub const INGEST_CPU_WEIGHT: f64 = 1.0; pub const QUERY_MEM_WEIGHT: f64 = 1e-9; pub const QUERY_CPU_WEIGHT: f64 = 1.0; + +/// Subpopulation count: 1 if subpopulation_aware else the distinct label-group +/// count for this config. The label-group count isn't profiled yet (needs +/// Prometheus series-count data) — use 1 as a placeholder; both branches +/// collapse to the same value until that lands. +pub const SUBPOPULATION_COUNT: f64 = 1.0; diff --git a/asap-planner-rs/src/optimizer/cost_model.rs b/asap-planner-rs/src/optimizer/cost_model.rs index b43797e0..b82015ee 100644 --- a/asap-planner-rs/src/optimizer/cost_model.rs +++ b/asap-planner-rs/src/optimizer/cost_model.rs @@ -4,7 +4,7 @@ use super::candidate_gen::CandidateConfig; use super::constants::{ EXACT_QUERY_CPU_SECS, INGEST_CPU_WEIGHT, INGEST_MEM_WEIGHT, INSERT_CPU_SECS, MEM_BYTES_PER_INSTANCE, MERGE_CPU_SECS, QUERY_CPU_SECS, QUERY_CPU_WEIGHT, QUERY_MEM_WEIGHT, - SUBTRACT_CPU_SECS, + SUBPOPULATION_COUNT, SUBTRACT_CPU_SECS, }; use super::sketch_properties::sketch_properties; use super::solution::{QueryMethod, AQE}; @@ -75,11 +75,7 @@ pub fn ingest_cost( return 0.0; // EXACT: no streaming config deployed. }; - // Subpopulation count: 1 if subpopulation_aware else the distinct - // label-group count for this config. The label-group count isn't profiled - // yet (needs Prometheus series-count data) — use 1 as a placeholder; both - // branches collapse to the same value until that lands. - let subpopulation_count = 1.0_f64; + let subpopulation_count = SUBPOPULATION_COUNT; // Defensive floor: slide_interval_ms is a plain u64 on a widely-shared struct; // guard against div-by-zero producing `inf` and poisoning cost comparisons. @@ -112,7 +108,7 @@ pub fn query_cost( }; // Subpopulation count; see ingest_cost comment. - let subpopulation_count = 1.0_f64; + let subpopulation_count = SUBPOPULATION_COUNT; let props = sketch_properties(agg_config.aggregation_type); let (cpu, mem) = match &candidate.query_method {