Skip to content

transform: algorithmic improvements to optimizer CPU hotspots#35297

Closed
def- wants to merge 1 commit intoMaterializeInc:mainfrom
def-:pr-optimizer-opt
Closed

transform: algorithmic improvements to optimizer CPU hotspots#35297
def- wants to merge 1 commit intoMaterializeInc:mainfrom
def-:pr-optimizer-opt

Conversation

@def-
Copy link
Contributor

@def- def- commented Mar 2, 2026

Profiling shows EquivalencePropagation alone consuming ~24% of total optimizer CPU. This commit makes several algorithmic improvements to reduce cloning, redundant work, and fixpoint iterations:

EquivalencePropagation (equivalence_propagation.rs):

  • Precompute base = join_equivs + outer_equivs once per Join, then clone per child, instead of cloning both separately N times
  • Add could_apply() guard to skip clone+reduce_expr+reduce+rollback for expressions the reducer's remap cannot affect
  • Remove redundant minimize() after permute() in Join input setup, since permute() already calls minimize(None) internally
  • Replace full relation.clone() for change detection with a Cell<bool> flag set conservatively at mutation sites

EquivalenceClasses (analysis/equivalences.rs):

  • Add could_apply() method to ExpressionReducer trait that walks the expression tree checking if any subexpression matches a remap key
  • Skip clone+reduce in minimize_once() for literals and column refs

RedundantJoin (redundant_join.rs):

  • Remove all redundant join inputs in one pass instead of one per fixpoint iteration, avoiding costly re-runs of all transforms for each removal

@github-actions
Copy link

github-actions bot commented Mar 2, 2026

Thanks for opening this PR! Here are a few tips to help make the review process smooth for everyone.

PR title guidelines

  • Use imperative mood: "Fix X" not "Fixed X" or "Fixes X"
  • Be specific: "Fix panic in catalog sync when controller restarts" not "Fix bug" or "Update catalog code"
  • Prefix with area if helpful: compute: , storage: , adapter: , sql:

Pre-merge checklist

  • The PR title is descriptive and will make sense in the git log.
  • This PR has adequate test coverage / QA involvement has been duly considered. (trigger-ci for additional test/nightly runs)
  • If this PR includes major user-facing behavior changes, I have pinged the relevant PM to schedule a changelog post.
  • This PR has an associated up-to-date design doc, is a design doc (template), or is sufficiently small to not require a design.
  • If this PR evolves an existing $T ⇔ Proto$T mapping (possibly in a backwards-incompatible way), then it is tagged with a T-proto label.
  • If this PR will require changes to cloud orchestration or tests, there is a companion cloud PR to account for those changes that is tagged with the release-blocker label (example).

@def- def- force-pushed the pr-optimizer-opt branch from f6efad8 to c70badc Compare March 2, 2026 13:24
Profiling shows EquivalencePropagation alone consuming ~24% of total
optimizer CPU. This commit makes several algorithmic improvements to
reduce cloning, redundant work, and fixpoint iterations:

**EquivalencePropagation (equivalence_propagation.rs):**
- Precompute `base = join_equivs + outer_equivs` once per Join, then
  clone per child, instead of cloning both separately N times
- Add `could_apply()` guard to skip clone+reduce_expr+reduce+rollback
  for expressions the reducer's remap cannot affect
- Remove redundant `minimize()` after `permute()` in Join input setup,
  since `permute()` already calls `minimize(None)` internally
- Replace full `relation.clone()` for change detection with a
  `Cell<bool>` flag set conservatively at mutation sites

**EquivalenceClasses (analysis/equivalences.rs):**
- Add `could_apply()` method to `ExpressionReducer` trait that walks
  the expression tree checking if any subexpression matches a remap key
- Skip clone+reduce in `minimize_once()` for literals and column refs

**RedundantJoin (redundant_join.rs):**
- Remove all redundant join inputs in one pass instead of one per
  fixpoint iteration, avoiding costly re-runs of all transforms for
  each removal

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@def- def- force-pushed the pr-optimizer-opt branch from c70badc to 4bdcf7c Compare March 2, 2026 13:26
@def- def- closed this Mar 3, 2026
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.

1 participant