Repository navigation
Conversation
… JSON did (canonical form failing) The canonical form's tests (crates/types/src/canonical_form/tests.rs): on every pair of sample values (every float class, skipped fields, strings that need escaping) typed equality confirmed by equal canonical forms decides as typed equality confirmed by equal JSON did, and equal canonical forms hash alike; signed zeros differ only under SignedZeros; every NaN is one value; skipped fields and adjacent strings stay apart. The memo's same_expression_decides_as_json_did checks the same on memo expressions and DDSketch θ. The canonical form is a todo!() stub here (5 tests fail); hash-consing still compares JSON behind its new signatures (its tests pass). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ot JSON Memo hash-consing confirmed typed equality with equal JSON texts and hashed expressions by their JSON: on a 100-query backend workload, add_candidate's scan confirmed 1.5M typed-equal operators through serde_json (about 1.4 s of planning CPU; find_or_add_group's serialization was 1,256 calls, about 1.5 ms; SketchParams' hash was not called). - asap_types::canonical_form: a serde Serializer writing a compact, self-delimiting binary encoding of the serde data model into a hasher (canonical_hash) or two reused thread-local buffers (same_canonical_form). Floats as bit patterns: under SignedZeros +0 and -0 differ (as their JSON texts did) and every NaN is one value; under NumericEquality +0 and -0 are one value too (a hash consistent with ==). Typed == (which rejects NaN) confirmed by equal canonical forms decides exactly as typed == confirmed by equal JSON did. - same_candidate runs every typed comparison (input requirements, operator, θ) before writing any canonical form: candidates of one group mostly share their operator and differ in θ. - find_or_add_group keeps only group ids per hash, no serialized text. - SketchParams' Hash feeds its canonical form (NumericEquality) to the hasher instead of hashing a JSON string. The Stage 2 JSON output (memo, every candidate, Stage 1 and Stage 2 lists) is byte-identical to the base on four workloads. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n and answers no lightcone query (failing) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A workload's last QueryWorkload::optional_query_count queries are planned with the others (Stages 0-2 see them, so the plan may read their states) but Stage 3 does not answer them: the plan has no root, query text or cost for them. Answering one is never cheaper (every cost term is non-negative and an answer only adds rows and terms), so Stage 3 leaves them unanswered. IntentFull under cost model 1 plans the intent once with its lightcone queries optional instead of planning it with and without them: the plan is no dearer than either, and lightcone_query_indices is empty. Under cost model 3 it keeps the two plans and the better one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
scaling/backend.s10000.n100),add_candidateranserde_jsonon 1.5M pairs of typed-equal operators, which took about 1.4 s of planning CPU.same_candidatenow runs every typed comparison before it writes any canonical form.IntentFullnow plans once, with its lightcone queries optional (planned with the others but never answered), instead of twice. On all 24intents/configs/*.c1r1configs the plan costs the same (12) or slightly less (12, e.g. slo 6.635858 → 6.635756 per second). Intent planning time summed over the configs drops 3.86 s → 2.62 s (−32%, release build); several configs with lightcone queries plan in about half the time (SB 0.114 → 0.057 s, drill_cnt 0.118 → 0.052 s).Review guide
feat/sil-intent(feat(sil): plan SIL intents: parse/check, lowering, hole guard, planning modes, group latency (L_G) #1553). This draft is stacked on it.crates/types/src/canonical_form.rs: the encoding and the float policy in its module doc;crates/types/src/stages/logical/memo/hash_consing/mod.rs:same_value,same_expression,expression_hash,same_candidate.memo/mod.rskeeps group ids per hash instead of(id, json).SketchParams'Hashfeeds the canonical form instead of a JSON string.==and equal canonical form" is exactly "typed==and equal JSON" (Algorithm changes, Correctness).test(sil)…andfeat(sil)…): readcrates/planner/src/intent.rs(plan_intents,IntentFull),crates/stage3-plan-selection/src/lib.rs(select_plan'soptional_query_count),plan.rsandreport.rs. About 15 files only addoptional_query_count: 0to struct literals (mechanical).Behavior: before → after
The same command, run on the base and on this branch:
--run-until stage2 --verbose --format jsonoutput (memo, candidates, Stage 1 and Stage 2 lists) has sha256b0af70a1…on both builds.This serves the eval's planning-time measurements on backend-like workloads, where Stages 0–2 are most of the planning time.
Part 2: a SIL intent (
intents/configs/OB.c1r1, under cost model 1):plan_intents(..., IntentFull)planned the intent twice, without and with one lightcone query per IN-list reader, and kept the cheaper plan. The plan with lightcones answered each lightcone query: it had a root and query text for each, and charged its small request cost. Planning took 0.412 s, at a cost of 11.720665 per second.optional_query_countqueries. Stages 0–2 see them, so the dependent queries may read the lightcone states, but Stage 3 never answers them. Planning takes 0.309 s, at a cost of 11.720562 per second. The plan's roots and query texts are the intent's queries only, andlightcone_query_indicesis empty. TheIntentPlanJSON schema is unchanged.Interfaces
crates/types/src/canonical_form.rs(new module):The memo's crate-private functions (
hash_consing/mod.rs) change as follows.serialized_expressionandsame_serialized_expressionare removed.crates/types/src/workload/query.rs,crates/types/src/workload/planning.rs:/// A workload's queries; the type stays. pub struct QueryWorkload { pub language: QueryLanguage, pub query_batch: Option<Vec<BatchEntry>>, pub repeating_queries: Option<Vec<RepeatingEntry>>, pub group_latency_bounds: Vec<GroupLatencyBound>, + /// How many of the last queries are optional: planned with the others (their states may be + /// shared) but not answered (no root, query text or cost). Default 0, omitted from JSON when 0. + pub optional_query_count: usize, } pub enum WorkloadError { + /// Bad input: `optional_query_count` is larger than the query count. + TooManyOptionalQueries { optional: usize, queries: usize }, }crates/stage3-plan-selection/src/lib.rs,report.rs:pub fn select_plan( physical: &PhysicalASAPMemoCandidates, entries: &[QueryWorkloadEntry], group_latency_bounds: &[GroupLatencyBound], + optional_query_count: usize, data: &DataWorkload, cost_inputs: &CostInputs, final_results_cache: FinalResultsCache, ) -> Result<(PhysicalASAPDAG, Selection), ErrorSelectingPlan>; pub enum ErrorSelectingPlan { + /// Bad input: an optional query has a scalar root (optional queries need operator roots, + /// so the other roots keep their positions). + OptionalScalarQuery { query: usize }, }Usage (part 1): nothing for a caller changes.
Memo::find_or_add_group(Stage 0, the Pass 1 and Pass 2 rules) hashes the expression withcanonical_hash, then confirms a bucket hit with typed==andsame_canonical_form.Memo::add_candidatecompares input requirements, the operator and θ with typed==first, then confirms withsame_canonical_form. The planner's output is unchanged; see Behavior.Usage (part 2): a SIL intent such as
q1 EVERY 10s: ($Y, _) := SELECT host, count(*) … LIMIT 5; q2: SELECT user, count(*) FROM auth WHERE host IN $Y …is planned withplan_intents(.., IntentPlanningOptions::default())(modeIntentFull).lower_intentsappends one lightcone query per IN-list reader (SELECT host, user, count(*) FROM auth … GROUP BY host, user).IntentFullsetsoptional_query_countto the number of lightcone queries and callsplan_installable.entries.len() - optional_query_countqueries. q2 may read the(host, user)state that Pass 2 shares with the lightcone group.IntentPlanhas roots for q1 and q2 only,lightcone_query_indices: [], and the report'scost_per_secondcovers q1 and q2 (checked bythree_modes_give_different_plansandoptional_query_is_planned_but_not_answered).Algorithm changes
Memo hash-consing equality
Problem: to confirm typed equality, the planner wrote both values as JSON. That meant escaping every string and formatting every float, on 1.5M pairs on b100.
Before:
same_value(a, b) = a == b && json(a) == json(b), and the hash was SipHash ofjson(expr).After:
same_value(a, b) = a == b && canonical(a) == canonical(b), and the hash is SipHash fed the canonical form directly. The canonical form is a self-delimiting encoding with one tag byte per serde event:same_candidatechecks input requirements, then operator==, then θ==, and only then the canonical forms. Most typed-equal operators belong to candidates that differ in θ, and these are now rejected without writing anything.Correctness: the decision is the same as before on every pair of values:
==:==;==and have equal bits, as their JSONnulls were equal;==, but their bits differ, as0.0and-0.0did in JSON;canonical_form::tests::decides_as_json_did_on_every_pair(every float class, skipped fields, strings that need escaping) andhash_consing::tests::same_expression_decides_as_json_did(memo expressions and DDSketch θ). End to end, the Stage 2 output is byte-identical on b100, n100, m8u and rh8.Complexity: the same traversal as before, without string escaping or float formatting. Hashing allocates nothing; comparison reuses two thread-local buffers. The memo no longer stores one JSON string per shareable group.
Measured on b100, as the minimum of 3–5 alternating runs on a shared host at load 80–110:
On n100 the whole planner goes from 27.90 s to 27.18 s; the MILP is most of its time.
Assumptions and limits:
SketchParams'HashusesNumericEquality, so it is consistent with its derived==. The JSON hash it replaces put +0 and −0 in different buckets.SIL
IntentFull: one plan with optional lightcone queriesProblem:
IntentFullplanned every intent with lightcone queries twice, once without them and once with all of them answered. That doubled planning time, and it could only keep all of the lightcones or none of them.Before (
plan_intents):After:
optional_query_count) and plan once.Stage 3 (
select_plan) leaves every optional query unanswered: no (C) row, no root and no cost terms. Stages 0–2 still plan them, so the dependent queries may read their states. If that plan fails, the plan without lightcones is used, as before. Under cost model 3 the old two-plan comparison is kept.Correctness: the one plan's feasible set contains both of the old plans' selections, minus the lightcone roots themselves:
Answering an optional query only adds rows and non-negative terms, so leaving it unanswered is optimal, and the result is never dearer than either old plan. Checks:
intent_full_once_is_no_dearer_than_two_passes(SIL tests) and the ignoredintent_full_once_is_no_dearer_on_intent_configs(all 24*.c1r1configs, 12 equal and 12 cheaper);optional_query_is_planned_but_not_answered(facade).Complexity: one planning run instead of two. Summed over the 24 configs, planning time goes from 3.86 s to 2.62 s (release build, combined branch). An earlier run of part 2 alone on another host measured 9.58 s → 6.33 s.
Assumptions and limits:
lowest_mean_latency),select_planrefuses optional queries, andIntentFullkeeps planning twice.Decisions and open questions
Hash/Eqacross the IR. About 40 IR fields aref64; deriving would need hand-written impls or wrapper types on each of them, and would changePartialEqelsewhere. The canonical form covers every type in a memo expression in one ~300-line module and decides exactly as the JSON did.lightcone_query_indicesis always empty and the plan has no lightcone roots or query texts; the dependent queries read the lightcone states directly. A consumer that expected lightcone roots in the plan must not rely on them. The alternative, keeping their roots, would charge their request cost for a query that is never issued.same_valuefromadd_candidateas the hot site: 1,507,935 calls, 1.44 s.serialized_expressionhad 1,256 calls (1.5 ms), andSketchParams::hashwas never called.Verification
cargo test -p asap-types --libtodo!()canonical formcargo clippy -p asap-types --all-targets --features test-support -D warningscargo fmtcargo test -p asap-plan-selection --libasap-stage3-plan-selection).asap-stage0-memo: 9 passed; Pass 1: 41 passed; Pass 2: 40 passed. Part 1 treecorpus_snapshots(release, including ignored)corpus_plans_match_snapshots,sketch_plans_match_snapshots,pruning_keeps_every_snapshot_optimum, …). Part 1 tree|
cargo test -p asap-planner --test planner -- sil_intents e2e_plan(combined tree) | 35 passed, 1 ignored | the ignored test needsASAP_SIL_INTENT_CONFIGS|| Part 2 alone:
asap-stage3-plan-selection --lib,asap-types --lib,asap-plannerandasap-planner-cli(all targets, including corpus snapshots), fmt, clippy | all passed | run on the part 2 tree before the cherry-pick ||
intent_full_once_is_no_dearer_on_intent_configs, release | 1 passed: 12 configs equal, 12 cheaper, none dearer (combined branch) | || The same, debug build | panics in a
debug_assertatcost.rs:1100("candidates with the same family and θ fold different rows", an exact CountSummaryAggvs aSummaryMerge) | The panic is in the test's old two-pass baseline (all lightcones answered), not in the new path.cost.rsis unchanged here. A follow-up issue should look at it. |Planning time on the combined branch (whole planner, minimum of 3 alternating runs, shared host):
The Stage 2 output stays byte-identical on b100 and n100 with both parts applied.
New tests:
decides_as_json_did_on_every_pair: on every pair of sample values, the canonical decision equals the JSON decision, and equal canonical forms hash alike.signed_zeros_differ_only_under_signed_zeros,every_nan_is_one_value: the float policy.skipped_fields_keep_fields_apart,strings_and_sequences_are_delimited: injectivity.same_expression_decides_as_json_did: the same equivalence on memo expressions (literals of every float class, quantiles, filters) and DDSketch θ.Follow-ups
lowest_mean_latency),IntentFullstill plans twice, andselect_planrefuses optional queries. Optional queries must come last and have operator roots. The debug-builddebug_assertatcost.rs:1100on intent configs is not addressed here.🤖 Generated with Claude Code