Repository navigation
fix(cost): stored view windows have a decoded and a stored size; rows hold an offset and a key per label column (#1486) - #1487
Merged
Merged
Conversation
zzylol
marked this pull request as ready for review
November 24, 2026 20:58
This was referenced Nov 24, 2026
…ize per state (#1486) Failing tests for #1486, before the fix: a per-series row holds a 4-byte state offset and a 4-byte key per label column beside its state; a measured stored_bytes_per_state gives the bytes in the view's files (disk, writes, cold reads) while memory keeps decoded bytes; the cache bound counts decoded bytes; the calibration gate compares bytes per window with the stored size.
…ffset and a key per label column (#1486) A view's window is charged at two sizes: its decoded bytes for memory (resident and building windows, the cache bound) and its bytes in the view's files for disk, disk writes and cold reads. The stored size is the window's states at a measured stored_bytes_per_state (file bytes per state's row), else the decoded size. A per-series row holds a state offset and a dictionary key per label column (state_offset_bytes_per_row and key_bytes_per_label_column, 4 each), replacing the fixed 72-byte stored_row_bytes_beside_state. The calibration gate compares bytes per window with the stored size.
Stored size only for outputs of states, and a measured entry giving stored_bytes_per_state without a sketch or exact state is refused (S4); separate defaults for the row layout fields; clearer names (stored_output_bytes, decoded_to_stored_bytes); detail text says decoded vs in files; test and doc wording; library-api lists the new field.
…d sizes (#1486) Only cost numbers and byte detail strings change; every plan selects the same nodes.
zzylol
force-pushed
the
test/1486-stored-bytes
branch
from
November 26, 2026 05:31
9ee46b3 to
1eb60ce
Compare
This was referenced Nov 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stored_bytes_per_state(file bytes per state's row), else the decoded size.Review guide
main(241353319). Commits:653510468: the failing tests, already approved.crates/cost/src/node/usage/mod.rs:stored_output_bytes,decoded_to_stored_bytes, and the window-cache branch ofnode_usage_and_cost_terms.crates/cost/src/node/state_bytes/mod.rs:state_row_bytes_beside_state.crates/cost/src/plan/cost.rs:window_cache_charges.crates/stage3-plan-selection/src/resident_windows.rs:resident_reads.stored_bytes_per_statethreaded throughcrates/cost/src/measured.rs: interpolation identical tomemory_bytes_per_state, plus validation.crates/planner/src/installable/mod.rs.deployment_exclusionsobserved costs;lowest_mean_latencya18;stage3_objectivean_instant_at_end_input_shares_the_evaluation_context;planner_fuzzwitness workload;state_bytesunit test default (72 → 12).Behavior: before → after
max_over_time(m[5m])every 10 s over 1,000 gauge series is one ingestion-time chain of 10 s windows, under a 60 s window cache. The chain's measured entry is{"exact": "Max", "memory_bytes_per_state": 16, "stored_bytes_per_state": 3.2}.unknown field stored_bytes_per_statebytes_per_window(decoded, memory)stored_bytes_per_window(files)disk_bytesdisk_written_bytes_per_secondaverage_memory_bytesstored_bytes_per_stateThis makes the cost model's storage estimates match measured execution, so that disk limits and disk cost select the plan the executor can actually hold.
Interfaces
crates/cost/src/measured.rs/// One measured entry per (operator, phase, family); stays. pub struct OperatorCost { pub operator: OperatorKind, pub phase: Option<ExecutionTiming>, pub sketch: Option<SketchParams>, pub exact: Option<ExactKind>, pub measure: Option<String>, pub ns_per_unit: f64, pub ns_per_invocation: f64, pub memory_bytes_per_state: Option<f64>, + /// For a node that keeps summary state: the bytes one state's row takes in a stored view's files, + /// as the executor writes them (file bytes ÷ states, keys and offset included). Sizes the view's + /// disk, disk writes and cold reads. `None` (default): stored = decoded. Needs `sketch` or `exact`. + pub stored_bytes_per_state: Option<f64>, pub ns_per_state_emitted: f64, pub measured_series_count: Option<u64>, pub measures: Vec<String>, } /// A node's unit price from its entry or interpolated between two; stays. pub struct UnitPrice { pub ns_per_unit: f64, pub ns_per_invocation: f64, pub memory_bytes_per_state: Option<f64>, + /// File bytes per state's row (`OperatorCost::stored_bytes_per_state`), interpolated like memory bytes. + pub stored_bytes_per_state: Option<f64>, pub ns_per_state_emitted: f64, pub outside_measured_scale: bool, }crates/cost/src/model.rs/// How the executor runs a plan; stays. pub struct DataPlaneExecution { pub ingest_threads: Option<u32>, pub precompute_threads: u32, pub query_threads: u32, pub allowed_lateness_ms: u64, pub max_thread_utilization: f64, pub ingest_work_at_refresh: bool, pub view_window_cache: Option<ViewWindowCache>, pub kept_query_time_results: Option<KeptQueryTimeResults>, pub answer_cache: Option<AnswerCache>, - pub stored_row_bytes_beside_state: u64, + /// Bytes a stored per-series state's row holds for its state's offset in the state column. Default 4. + pub state_offset_bytes_per_row: u64, + /// Bytes a stored per-series state's row holds per label column, each text column (the series + /// identity is one): a dictionary key; label text is kept once per series per file. Default 4. + pub key_bytes_per_label_column: u64, }stored_row_bytes_beside_stateis removed. The 64-byte series key it assumed is not how rows are stored, and a cost-inputs file that still sets it is refused.crates/cost/src/node/usage/mod.rs/// A node's memory, disk and disk traffic; stays. pub struct NodeMemoryAndDisk { pub average_memory_bytes: f64, pub peak_memory_bytes: u64, /// An ingestion-time view's decoded bytes per window (one output), as memory holds it; 0 for any other node. pub bytes_per_window: u64, + /// An ingestion-time view's bytes per window in its files (disk, disk writes, cold reads); + /// `bytes_per_window` without a measured `stored_bytes_per_state`; 0 for any other node. + pub stored_bytes_per_window: u64, pub disk_bytes: u64, pub disk_written_bytes_per_second: f64, pub disk_read_bytes_per_second: f64, } /// An in-memory ingestion-time view's windows under a window cache; stays. pub struct CachedViewWindows { /// The decoded bytes of one window, as the cache holds it. pub bytes_per_window: u64, + /// The bytes of one window in the view's files, as a cold read reads it. + pub stored_bytes_per_window: u64, pub width_ms: u64, pub retained: u64, }crates/cost/src/node/analytical.rspub enum AnalyticalCostError { + /// Bad input: a measured entry gives `stored_bytes_per_state` without a sketch or exact accumulator. + StoredBytesWithoutState(String), }The
AnalyticalCostErrorenum stays; only the new variant is shown. The plan report's per-nodePredictedNodeUsage(crates/planner/src/installable/mod.rs) gainsstored_bytes_per_window(serde(default)).tools/calibration_gatecompares measured bytes/window with it when present.Usage (S1 in
crates/integration-tests/tests/storage_costs.rs, run at the PR head):Algorithm changes
Stored view sizing
state= a window's decoded bytes (out.bytes, with the row overhead fixed at 72 B beside each per-series state).state× windows on disk; writes =state÷ width.state.state= decoded bytes, with row overheadstate_offset_bytes_per_row+key_bytes_per_label_column× text columns (state_row_bytes_beside_state).stored_output_bytes=out.rows× measuredstored_bytes_per_statewhen the node outputs states and the table has it; elsestate.disk_bytes_chargedand writes usestored_output_bytes. For disk-medium lifetimes, a decoded total is scaled by stored ÷ decoded (decoded_to_stored_bytes).window_cache_charges(plan cost) andresident_reads(Stage 3) keep decoded bytes for residency and the cache bound, and readstored_bytes_per_windowper cold window.storage_costsK/F/D tests). Memory never reads the stored size (S1, D4, D5). Tests R1–R3 and S1–S4 cover this, along with D4, D5 and gate K10.Decisions and open questions
Decided (2026-11-24, by the user on #1486):
stored_bytes_per_stateentries, each counting the whole stored row per state;Needs reviewer decision:
measured_rows_per_stateto an entry and interpolate log–log by a node's rows per state, asmeasured_series_countalready does by series count.Verification
Tests
All tests below were run at the PR head, with
cargo test(cargo-nextest is not installed here).cargo test -p asap-integration-tests --test integrationstorage_costs::(17)cargo test -p asap-cost(lib +measured_operation_costs)cargo test -p asap-stage3-plan-selection --libcargo test -p asap-devtools(lib, bins,devtools,goldens,corpus_snapshots, lane conformance)corpus_plans_match_snapshots,sketch_plans_match_snapshots) are#[ignore]tests and did not run here. Run with--include-ignored, they failed at this head (see Snapshot changes).cargo test -p asap-plannerpython3 -m unittest test_calibration_gatecargo clippy --workspace --all-targets -- -D warnings,cargo fmt --checkChanged expectations of existing tests
state_bytes_per_row_leave_out_what_the_row_holds_beside_its_statedeployment_exclusions, observed plan costslowest_mean_latency::a18, renameda18_a_bound_at_the_selected_latency_keeps_a_plan_within_itSummaryAggplan of 30.301 ms. Under the bound it finds anAggregateplan of 30.300 ms, which is faster and in bound.stage3_objective::an_instant_at_end_input_shares_the_evaluation_context@ end()query cannot read it. The test is about sharingm[5m]in the evaluation context.planner_fuzzsummed_over_a_chainTimeRangeover one chain.Snapshot changes
After the rebase onto main (after #1519–#1521), run with
cargo test --release -p asap-planner-cli --test goldens --test corpus_snapshots -- --include-ignored. The snapshots are regenerated withUPDATE_SNAPSHOTS=1and now pass (goldens 14, corpus + sketch 9).cost_per_second,average_memory_bytes,peak_memory_bytesand the byte counts indetailstrings change.Example, o11y_bench q18 (same nodes):
Tests after the rebase onto main
cargo test -p asap-costcargo test -p asap-stage3-plan-selectioncargo test -p asap-plannercargo test -p asap-integration-tests --test integrationcargo test -p asap-devtoolsplanner_fuzzand the other devtools tests 31)cargo test --release -p asap-planner-cli --test goldens --test corpus_snapshots -- --include-ignoredpython3 -m unittest test_calibration_gatecargo fmt --check,cargo clippy -p asap-cost -p asap-stage3-plan-selection -p asap-planner -p asap-devtools -p asap-integration-tests --all-targets -- -D warningsNew tests
stored_bytes_per_statewithout a state family is refused. It was written together with the fix, not before it.Reviews
Four separate reviewers looked at the diff; each review was read-only.
library-api.mdlists the fieldchain_node_with_table;measured_stored_bytes_per_stateinlined at its use; the disk-medium chain multiplies directlydecoded_to_stored_bytes,stored_output_bytes; detail strings say decoded vs in files; a18 renamed;analytical-resource-cost.mdrow sentence updatedAcceptance A1–A3: calibration gate on the compact-format run
The gate was run on the run's plan, workload and measured file (format 4, +31 min), using this branch's planner (
--price-plan).Of the 23 per-view bytes/window rows still failing in the different-run variant:
Follow-ups
stored_bytes_per_stateforSummaryMergeWindowsentries as well as chains, or wider levels are charged decoded.