Skip to content

Record whether an array has been optimized - #11089

Merged
robert3005 merged 3 commits into
developfrom
rk/optimized-state
Nov 2, 2026
Merged

robert3005 merged 3 commits into
developfrom
rk/optimized-state

Conversation

@robert3005

@robert3005 robert3005 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Part 1 of 4 of a split of #10793. The stack: #11089 → #11090 → #11091 → #11092.

The optimizer now records which arrays it has already optimized, so it does not try the rules on them again.

Changes

  • Each array has an OptimizedState. A new array starts unoptimized.
  • optimize_recursive marks every node that it returns. optimize, optimize_ctx and optimize_recursive return a marked array without trying any rule.
  • SerializedArray::decode marks every node that it decodes. Thus arrays that the file, IPC and plan v2 readers read are not optimized again.
  • ArrayRef::inner_mut clears the mark, because the caller can change the array.

@robert3005
robert3005 added this pull request to stack #11093 November 2, 2026 12:06
@robert3005 robert3005 added the changelog/performance A performance improvement label Nov 2, 2026
@robert3005
robert3005 marked this pull request as ready for review November 2, 2026 12:06
@robert3005 robert3005 changed the title rk/optimized state Record whether an array has been optimized Nov 2, 2026
@codspeed

codspeed Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 0.83%

1 warning

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚡ 7 improved benchmarks
❌ 3 regressed benchmarks
✅ 2308 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ CPU Simulation filter_powerlaw_by_random[10000] 764.1 ns 1,790.8 ns -57.33%
❌ Walltime threshold_neon[80] 3.4 µs 3.9 µs -12.07%
❌ Walltime threshold_neon[64] 2.6 µs 2.9 µs -11.52%
⚡ CPU Simulation take_map[(0.1, 0.5)] 174.6 µs 144.2 µs +21.07%
⚡ CPU Simulation bench_compare_varbin[(50000, 2)] 160.9 µs 133.5 µs +20.5%
⚡ CPU Simulation bench_compare_varbin[(50000, 64)] 163 µs 135.5 µs +20.29%
⚡ CPU Simulation bench_compare_sliced_dict_varbinview[(7500, 10000)] 226.8 µs 200.4 µs +13.16%
⚡ CPU Simulation bench_compare_sliced_dict_varbinview[(10000, 10000)] 233 µs 206.7 µs +12.72%
⚡ CPU Simulation bench_compare_sliced_dict_varbinview[(1000, 10000)] 88.6 µs 78.8 µs +12.44%
⚡ CPU Simulation take_map[(0.1, 1.0)] 229.3 µs 208.3 µs +10.08%

Tip

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


Comparing rk/optimized-state (a8457ad) with develop (7c9bb58)

Open in CodSpeed

Each array now has an OptimizedState. optimize_recursive marks every node
it returns, so it returns a marked array again without trying any rule.
optimize and optimize_ctx also return a marked array as it is.

Arrays decoded from their serialized form are marked as optimized.
Changing a uniquely owned array in place clears the mark.

Signed-off-by: Robert Kruszewski <github@robertk.io>
OptimizedState::clear had a single caller. inner_mut now resets the
AtomicBool through get_mut, which is pub(crate).

Signed-off-by: Robert Kruszewski <github@robertk.io>
Comment thread vortex-array/src/optimizer/mod.rs Resolved
The optimized mark promises only that no rule applies given the
encodings, dtypes, slots and data of the subtree, which do not change
while the array is shared. Document the cases where an array must stay
unmarked or clear its mark: an in-place change, a rule that reads state
set after the pass such as statistics, and a session with more kernels.
Also document why Relaxed ordering is correct, and when the flag needs
Release and Acquire.

Signed-off-by: Robert Kruszewski <github@robertk.io>
@robert3005
robert3005 merged commit 8448fa6 into develop Nov 2, 2026
78 of 79 checks passed
@robert3005
robert3005 deleted the rk/optimized-state branch November 2, 2026 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/performance A performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants