Skip to content

[codex] Optimize primitive arg layout fast paths#845

Draft
MilkBlock wants to merge 3 commits intoegraphs-good:mainfrom
MilkBlock:codex/rust-rule-layout-fastpath-pr
Draft

[codex] Optimize primitive arg layout fast paths#845
MilkBlock wants to merge 3 commits intoegraphs-good:mainfrom
MilkBlock:codex/rust-rule-layout-fastpath-pr

Conversation

@MilkBlock
Copy link
Copy Markdown
Contributor

@MilkBlock MilkBlock commented Apr 12, 2026

This PR combines two tightly-related pieces needed to make the primitive-argument layout optimization meaningful on real workloads.

  1. A narrow runtime fast path in core-relations for the single-External shape: when an action batch executes exactly one external call whose arguments are a consecutive variable window in the current struct-of-arrays bindings layout, the runtime batch-transposes once into a row-major scratch buffer and then invokes the external function row-by-row from that transposed block.
  2. A rule-local query-entry normalization in core-relations::RuleBuilder::build_with_description(): for eligible single-external rules, external argument vars are normalized into a consecutive core-variable window while preserving their semantic order. This increases the hit rate of the runtime fast path in realistic workloads instead of relying on lucky pre-existing variable numbering.

The optimization is still intentionally scoped:

  • no new public API
  • no ruleset-wide scheduling changes
  • no generalized argument-layout framework
  • fallback remains the old path for any rule shape that does not match the narrow optimized corridor

Focused validation performed:

  • cargo test -q -p egglog-core-relations run_instrs_single_external_borrowed_window_executes -- --nocapture
  • cargo test -q -p egglog-core-relations single_external_rule_normalizes_gap_vars_into_consecutive_window -- --nocapture
  • cargo test -q -p egglog-bridge constrain_prims -- --nocapture
  • cargo check -q

Downstream workload validation:

  • I compared eggplant math_microbenchmark before/after on the corresponding downstream dependency setup.
  • With the finer-grained internal breakdown enabled, the relevant stage improved as follows:
    • rewrites run_ruleset: 1.605385708 s -> 1.503743250 s (~6.3% faster)
    • total benchmark time: 3.005323708 s -> 2.813726958 s (~6.4% faster)

That is the reason these two changes are folded together here: the runtime transpose lane alone is too narrow to justify a broader performance claim, while the query-entry normalization makes the same lane actually trigger in the real single-external rule shapes we care about.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 12, 2026

Merging this PR will not alter performance

✅ 38 untouched benchmarks
⏩ 190 skipped benchmarks1


Comparing MilkBlock:codex/rust-rule-layout-fastpath-pr (ef04f91) with main (21b99b6)

Open in CodSpeed

Footnotes

  1. 190 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@MilkBlock MilkBlock force-pushed the codex/rust-rule-layout-fastpath-pr branch 2 times, most recently from 5bb2cb4 to ed766e0 Compare April 12, 2026 03:20
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 12, 2026

Codecov Report

❌ Patch coverage is 93.69369% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.29%. Comparing base (912663b) to head (ef04f91).
⚠️ Report is 110 commits behind head on main.

Files with missing lines Patch % Lines
core-relations/src/query.rs 92.75% 5 Missing ⚠️
core-relations/src/action/mod.rs 95.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #845      +/-   ##
==========================================
+ Coverage   81.54%   86.29%   +4.74%     
==========================================
  Files          88       85       -3     
  Lines       24112    23373     -739     
==========================================
+ Hits        19662    20169     +507     
+ Misses       4450     3204    -1246     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@MilkBlock MilkBlock force-pushed the codex/rust-rule-layout-fastpath-pr branch from a52475d to 98f72a4 Compare April 12, 2026 04:06
@MilkBlock MilkBlock force-pushed the codex/rust-rule-layout-fastpath-pr branch from 98f72a4 to 7336b22 Compare April 12, 2026 04:08
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