Skip to content

U3 (D-RU-3): cross-rule CSE in crepe-plan-probe - #1653

Draft
AdaWorldAPI wants to merge 7 commits into
mainfrom
ccr-d3ce1263-ied9yh
Draft

AdaWorldAPI wants to merge 7 commits into
mainfrom
ccr-d3ce1263-ied9yh

Conversation

@AdaWorldAPI

Copy link
Copy Markdown
Owner

What this adds

  • crepe-plan-probe/src/cse.rs — evaluate_shared. It makes the same rewrites as pipeline::evaluate and gives the same answer. The rules are split into groups. Each group:
    • lays out its distinct sides once, over one domain;
    • writes every rule as And(Sym(side));
    • with sharing on, turns parts that several rules share into lets (set_program::share) and runs them through relalg::run_program (U2).
  • Layout::Components: rules that share a side, directly or through other rules, share one table. A rule that shares nothing keeps its own table.
  • Layout::OneTable puts every rule into one table. It stays in as the measured counter-example.
  • native::tuples_over_mask: the per-rule tuple read, moved out into a helper so the shared tables can use it. Behaviour is unchanged; the existing 41 tests pass.
  • examples/rule_cse.rs: 256 rules Out(k,x,z) <- R_g(x,c), S_g(c,z), T(c,k), with 0 %, 50 % or 90 % of them using the same core. Four arms:
    • A: today's per-rule pipeline;
    • U: one table, with lets;
    • D0: components, no lets;
    • D: components, with lets.
    • CI runs the example's tests; the benchmark itself is not run in CI.

Measured

200,000 centers, release build, median of 3 runs:

core shared arm prepare rows laid out ops folds share (compile) tuples
0 % A 1851 ms 15.3 M 512 — — 132 ms
0 % U 2721 ms 15.3 M 512 2.4 ms 1.1 ms 259 ms
0 % D0 1794 ms 15.3 M 512 0.9 ms — 130 ms
90 % A 1777 ms 15.3 M 512 — — 142 ms
90 % D 1218 ms 6.2 M 283 1.2 ms 7.1 ms 169 ms
  • The gain comes from laying the core out once, not from the folds. At 90 % the core is laid out once instead of 230 times, which makes the run about 31 % faster overall.
  • The lets save ops (512 → 283) but almost no time. The folds take at most 2.4 ms, and finding the shared parts costs about 7 ms. That search is quadratic in the number of rules.
  • One table for all rules is slower than A when nothing is shared (prepare +47 %, tuple read about 2×). Every side is laid out densely over its table's domain, which is why tables are formed per group instead.

Correctness

  • Every arm, under both layouts, matches the reference evaluator (bag semantics), crepe! and ascent! (set semantics) and arm A. Checked at 0, 50, 90 and 100 % shared.
  • Bound demands go through the post filter, both with and without propagation.
  • Rejected: a side whose generation is stale, a generation vector of the wrong shape, and a program for a different version.
  • I disabled each of 7 checks in turn; each disable turned its test red.
  • Board: STATUS_BOARD D-RU-3 is now MEASURED; new entry entries/2026-10-21-u3-cross-rule-cse.md; added a note to the plan.

Open

  • share costs more than it saves when the planes are this small. Two options, neither measured yet: group star rules by identical core keys, or skip lets when a single plane is cheaper than the search.
  • Plan arms E (factorization), F (shared BIND) and H (JC batch through the same lets) are not built.

Generated by Claude Code

cse.rs lays out the distinct sides of all rules' stars once, over one
shared domain, writes each rule as And(Sym(side)), lifts parts two or
more rules share into lets (contract::set_program::share) and runs them
through relalg::run_program. The tuples are read per rule with
native::tuples_over_mask, the per-rule pipeline's own read, moved into a
helper (behaviour unchanged: the existing 41 tests pass).

examples/rule_cse.rs: 256 rules Out(k,x,z) <- R_g(x,c), S_g(c,z), T(c,k)
at a shared-core rate of 0/50/90 %. Arms A (per-rule pipeline), D0 (one
table, no lets), D (one table, lets). Tests: every arm equals the
reference evaluator (bags), crepe! and ascent! (sets), at 0, 50, 90 and
100 % shared; the shared core is one let and planes read are pinned;
nothing is lifted at 0 %; a stale side is refused.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VncKoyG6JkpsoqhqTGTv3f
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VncKoyG6JkpsoqhqTGTv3f
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VncKoyG6JkpsoqhqTGTv3f
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VncKoyG6JkpsoqhqTGTv3f
The first layout put every side of every rule over the union of all
centers. Measured at 200k centers, that made a workload with no shared
core slower than the per-rule path (prepare 2.84 s vs 2.09 s, tuples
293 ms vs 145 ms): each side is laid out densely over its table's
domain. Layout::Components gives one table per group of rules that
share a side, directly or through other rules; a rule that shares
nothing keeps a table of its own. Layout::OneTable stays as the
measured counter-example (arm U).

Tests: every arm under both layouts equals the reference, crepe! and
ascent!; at 0 % shared, Components lays out exactly the per-rule rows,
one table per rule; at 90 %, one group for core 0 plus one per other
rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VncKoyG6JkpsoqhqTGTv3f
@coderabbitai

coderabbitai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

2 participants