Drop the fallible dtype lookup from stats rewrites - #9652
Conversation
`BoundExpression` carries a dtype on every node, so a rewrite rule that needs a type does a field read. `StatsRewriteCtx::return_dtype` stayed behind from when the context held a scope and the lookup walked the subtree. It now clones the dtype and wraps an infallible read in a `VortexResult`, which hides that fact from rule authors. Remove it and read `BoundExpression::dtype` at the call sites. With the last fallible lookup gone, `geometry_and_constant` no longer needs the rewrite context or a result wrapper, and `non_nan_check` no longer needs the context at all. Acceptance and rejection of predicates are unchanged: `ensure_predicate` matches the same dtype, and the `.ok()?` in `stat_expr` guarded an error that could not occur. Signed-off-by: "Robert Kruszewski" <robert@spiraldb.com>
Merging this PR will degrade performance by 10.78%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | compact[(1024, 90)] |
1.3 µs | 1.5 µs | -11.14% |
| ❌ | Simulation | compact[(2048, 90)] |
1.4 µs | 1.5 µs | -10.72% |
| ❌ | WallTime | mul_u32_nonnull_avx512 |
5.6 µs | 6.2 µs | -10.48% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing perf/skip-recursive-predicate-revalidation (84c71a5) with develop (59a056d)
Footnotes
-
106 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. ↩
-
4 benchmarks were run, but are now archived. If they were deleted in another branch, consider rebasing to remove them from the report. Instead if they were added back, click here to restore them. ↩
|
Closing: keeping changes local per robert |
What
The tracked work item asked to replace a recursive tree-walking validation in the stats
rewrite with the dtype stored on each
BoundExpressionnode. That walk is already gone:#9192 replaced
expr.return_dtype(scope)with the field lookup, and it is ondevelop.What survived is the wrapper around it.
StatsRewriteCtx::return_dtypedates from when thecontext held a scope and the lookup walked the subtree. Today it clones the dtype and wraps
an infallible field read in a
VortexResult, which hides from rule authors that reading atype is free.
This removes it. Call sites read
BoundExpression::dtypedirectly.With the last fallible dtype lookup gone, two helpers simplify:
geometry_and_constantno longer needs the rewrite context or theVortexResultwrapper,so it returns a plain
Option.non_nan_checkno longer needs the context at all.Guarantees
Acceptance and rejection of predicates are unchanged:
ensure_predicatematchesDType::Bool(_)on the same value it did before..ok()?instat_exprguarded an error the lookup could not produce.Checks
cargo nextest run -p vortex-array -p vortex-spatial -p vortex-layout -p vortex-file—4041 passed, 1 skipped
cargo test --doc -p vortex-array— passcargo clippy --all-targets --all-features— cleancargo +nightly fmt --all🤖 Generated with Claude Code