8000 feat: cost-based not/or ordering (#205) by adityamukho · Pull Request #251 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content

feat: cost-based not/or ordering (#205) - #251

Merged
adityamukho merged 18 commits into
mainfrom
feature/issue-205-cost-based-optimizer
May 16, 2026
Merged

adityamukho merged 18 commits into
mainfrom
feature/issue-205-cost-based-optimizer

Conversation

@adityamukho
Copy link
Copy Markdown
Collaborator

Summary

  • Adds pattern_cost, branch_cost, clause_cost to optimizer.rs (unconditional, all targets)
  • Sorts not/not-join clauses cheapest-first in execute_query, execute_query_with_rules, and StratifiedEvaluator
  • Sorts or/or-join branches cheapest-first in apply_or_clauses (infrastructure for perf: short-circuit or/or-join branch evaluation using cost model #250)
  • Sorting gated on #[cfg(not(feature = "wasm"))] — small datasets + determinism on WASM

Closes #205

Test plan

  • All existing tests pass (cargo test)
  • 14 new unit tests for all cost tiers and variants in optimizer.rs
  • Integration test: not-clause ordering produces correct results
  • cargo clippy -- -D warnings clean
  • cargo fmt --check clean

🤖 Generated with Claude Code

adityamukho and others added 16 commits May 15, 2026 15:19
…le optimization)

Covers issues #207 and #206: extends optimizer::plan() to accept Expr
clauses and interleave them at the earliest position where their variables
are bound, and routes the StratifiedEvaluator mixed-rules path through
the updated planner.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…d rules)

TDD plan covering optimizer.rs, matcher.rs, executor.rs, evaluator.rs,
and a new Criterion benchmark. 9 tasks, each with exact file paths,
code blocks, and expected test output.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…#205)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add a concise 'WASM omission' comment at every existing and planned
#[cfg(not(feature = "wasm"))] ordering gate explaining why sorting is
disabled on WASM targets (small datasets, deterministic behaviour).
The full rationale lives in the selectivity_score() doc comment;
all other sites reference it with a short cross-reference.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…cost (#205)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Static 4-tier cardinality cost model. Unconditional (all targets).
Sorting call-sites gated on cfg(not(feature = "wasm")) added in next commit.
…se_cost (#205)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cheap filters run first; bindings rejected early never reach expensive filters.
Gated on cfg(not(feature = "wasm")) — small datasets + determinism on WASM.
Infrastructure for issue #250 (or short-circuit). All branches still evaluated.
Gated on cfg(not(feature = "wasm")). Also adds #[allow(dead_code)] to clause_cost
which is public API exercised in tests but not yet consumed by non-test call-sites.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ator (#205)

Consistent with executor.rs; cheap filters run first in mixed-rules loop.
Gated on cfg(not(feature = "wasm")).
#205)

Makes clause_cost reachable from production code (fixes dead_code lint).
Semantically identical: clause_cos
8000
t(Not(body)) == branch_cost(body).
@codecov
codecov Bot commented May 16, 2026
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.45455% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/query/datalog/executor.rs 75.00% 6 Missing ⚠️
src/query/datalog/evaluator.rs 87.50% 1 Missing ⚠️
src/query/datalog/optimizer.rs 95.65% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

adityamukho and others added 2 commits May 16, 2026 10:49
… unused_mut)

Gate pattern_cost / branch_cost / clause_cost and their tests behind
#[cfg(not(feature = "wasm"))] to match the call-sites that consume them.
Add #[cfg_attr(feature = "wasm", allow(unused_mut))] to `let mut` bindings
that are only mutated inside #[cfg(not(feature = "wasm"))] sort blocks.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…r allow instead of cfg gate (#205)

Spec requires pattern_cost/branch_cost/clause_cost to be available on all targets.
Only the sorting call-sites are gated on cfg(not(feature = "wasm")).
Use cfg_attr(feature = "wasm", allow(dead_code)) to silence the dead_code lint on wasm.
Cost-model unit tests also made unconditional (they don't run on wasm32 anyway).
@adityamukho
adityamukho merged commit d4bce55 into main May 16, 2026
36 checks passed
@adityamukho
adityam A0CA ukho deleted the feature/issue-205-cost-based-optimizer branch May 16, 2026 05:55
adityamukho added a commit that referenced this pull request May 17, 2026
Wave 2 (PRs #249, #251, #253) was missing from CHANGELOG.md, ROADMAP.md,
and TEST_COVERAGE.md:

- CHANGELOG.md: add Wave 2 section between Wave 3 and Wave 1 entries
- ROADMAP.md: add Wave 2 to timeline between Wave 1 and Wave 3
- TEST_COVERAGE.md: add Wave 2 completion status note (no new tests —
  all optimizer + benchmark work covered by existing 850 tests)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(post-1.0): cost-based optimizer extensions for new clause types

1 participant

0