Skip to content

Fix exponential stats rewrite for nested OR predicates - #9408

Merged
joseph-isaacs merged 3 commits into
developfrom
claude/zonemap-prune-performance-0lqpdu
Aug 14, 2026
Merged

Fix exponential stats rewrite for nested OR predicates#9408
joseph-isaacs merged 3 commits into
developfrom
claude/zonemap-prune-performance-0lqpdu

Conversation

@robert3005

Copy link
Copy Markdown
Contributor

binary_falsify recursively falsified both children of an Or node before checking EMIT_UNGUARDED_REWRITES, so every registered Binary rewrite rule repeated the full recursive rewrite of the subtree and then discarded all but one copy. That makes the falsify rewrite O(2^depth) for left-deep OR chains such as a = 1 OR a = 2 OR ... and O(n^2) for balanced OR trees: a 24-term chain took ~137s to rewrite and ~16x longer for every 4 additional terms.

`binary_falsify` recursively falsified both children of an `Or` node
before checking `EMIT_UNGUARDED_REWRITES`, so every registered `Binary`
rewrite rule repeated the full recursive rewrite of the subtree and then
discarded all but one copy. That makes the falsify rewrite O(2^depth)
for left-deep OR chains such as `a = 1 OR a = 2 OR ...` and O(n^2) for
balanced OR trees: a 24-term chain took ~137s to rewrite and ~16x longer
for every 4 additional terms.

Check the guard before recursing, mirroring the `And` arm (semantics
are unchanged: the guarded rule always produced `None` for `Or`). The
same 24-term chain now rewrites in ~120us and a 1000-term chain in ~8ms.

Adds a regression test that counts `Binary` rule visits to pin the
rewrite to one visit per node, and a falsifier shape test for `Or`.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014a8epAuP9LG1R5tHPL3qpi
Signed-off-by: Claude <noreply@anthropic.com>
Signed-off-by: Robert Kruszewski <github@robertk.io>
@codspeed-hq

codspeed-hq Bot commented Aug 14, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 0.59%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 1992 untouched benchmarks
⏩ 89 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation compress_fsst[(1000, 64, 8)] 1 ms 1.2 ms -12.23%
Simulation cold_misaligned[(64, 256)] 4.9 ms 4.4 ms +12.58%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing claude/zonemap-prune-performance-0lqpdu (0cc4ea7) with develop (9a584e4)

Open in CodSpeed

Footnotes

  1. 89 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.

Signed-off-by: Robert Kruszewski <github@robertk.io>
// Check before recursing: falsifying the children first would repeat the
// whole recursive rewrite once per registered `Binary` rule, which is
// exponential in `Or`-nesting depth for chains like `a = 1 OR a = 2 OR ...`.
if !P::EMIT_UNGUARDED_REWRITES {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did we merge this trait:

trait NonNanProof {
    const EMIT_UNGUARDED_REWRITES: bool;

    fn check(ctx: &StatsRewriteCtx<'_>, expr: &BoundExpression) -> VortexResult<NanCheck>;
}

@robert3005 robert3005 added the changelog/fix A bug fix label Aug 14, 2026
@joseph-isaacs
joseph-isaacs enabled auto-merge (squash) August 14, 2026 09:59
@joseph-isaacs
joseph-isaacs merged commit 93b0535 into develop Aug 14, 2026
103 of 105 checks passed
@joseph-isaacs
joseph-isaacs deleted the claude/zonemap-prune-performance-0lqpdu branch August 14, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants