Skip to content

perf(patches): take PiecewiseSequenceArray runs without expanding them - #11547

Open
robert3005 wants to merge 5 commits into
developfrom
claude/intelligent-johnson-cbr0hl
Open

robert3005 wants to merge 5 commits into
developfrom
claude/intelligent-johnson-cbr0hl

Conversation

@robert3005

@robert3005 robert3005 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Patches::take expanded PiecewiseSequenceArray indices into one index per element before it searched the patches. Sorted, non-overlapping runs are now merged with the sorted patch indices directly, so the cost depends on the number of runs and patches, not on the number of indices. Other piecewise indices fall back to the existing take, and SparseArray::take gets the same benefit.

🤖 Generated with Claude Code

robert3005 and others added 2 commits November 18, 2026 09:21
Adds take_piecewise benchmarks that take Patches with ascending
PiecewiseSequenceArray runs, next to take_piecewise_materialized, which
expands the same indices to a primitive array first. Patches::take
currently materializes piecewise indices itself, so the two match; the
follow-up optimisation takes the runs without expanding them.

Counts the 12 new benchmarks in scripts/codspeed_bench_counts.json for
the CodSpeed shard planner.

Signed-off-by: Robert Kruszewski <github@robertk.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gz5XNZn5EvWEDxkeJkJAFe
Patches::take and take_with_nulls now recognise PiecewiseSequenceArray
indices made of ascending, non-overlapping, unit-multiplier runs and
merge them with the sorted patch indices by galloping along both, so the
cost depends on the number of runs and patches rather than the number of
indices. The matched values are taken as a slice for a single run and as
a PiecewiseSequenceArray of contiguous runs otherwise. Other piecewise
indices fall back to the materialized take, as the fixed-width and
chunked take kernels already do via maybe_contiguous_slices.

take and take_with_nulls now share one implementation, and the chunked
take's contiguous_runs helper moves to the piecewise_sequence module so
both callers share it.

Signed-off-by: Robert Kruszewski <github@robertk.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gz5XNZn5EvWEDxkeJkJAFe
@robert3005
robert3005 force-pushed the rk/patches-piecewise-take-bench branch from f9667e5 to 583e8a0 Compare November 18, 2026 09:22
@robert3005
robert3005 force-pushed the claude/intelligent-johnson-cbr0hl branch from feebf22 to 0c14f56 Compare November 18, 2026 09:22
robert3005 and others added 2 commits November 18, 2026 10:12
Keep only take_piecewise at patch density 0.1 with run lengths 1, 16 and
256. CodSpeed compares each benchmark against its base, so the
materialized variant and the second density added little.

Signed-off-by: Robert Kruszewski <github@robertk.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gz5XNZn5EvWEDxkeJkJAFe
…t-johnson-cbr0hl

Signed-off-by: Robert Kruszewski <github@robertk.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gz5XNZn5EvWEDxkeJkJAFe
@robert3005 robert3005 added the changelog/performance A performance improvement label Nov 18, 2026
@robert3005
robert3005 marked this pull request as ready for review November 18, 2026 10:37
@codspeed

codspeed Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by ×2.1

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

⚡ 6 improved benchmarks
✅ 1976 untouched benchmarks
⏩ 57 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation take_piecewise[256] 177.3 µs 32.4 µs ×5.5
⚡ CPU Simulation take_piecewise[1] 395.7 µs 116.9 µs ×3.4
⚡ CPU Simulation take_piecewise[16] 153.3 µs 49.9 µs ×3.1
⚡ Walltime random_rotating_avx2[(0.9, 0.9, "self_90pct_mask_90pct")] 9.5 µs 8.3 µs +14.99%
⚡ CPU Simulation density_sweep_validity[0.02] 59.4 µs 52.4 µs +13.28%
⚡ CPU Simulation density_sweep_random[0.05] 122.8 µs 108.5 µs +13.16%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing claude/intelligent-johnson-cbr0hl (9c2ee30) with develop (d368834)

Open in CodSpeed

Footnotes

  1. 57 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. ↩

robert3005 added a commit that referenced this pull request Nov 19, 2026
## Summary

Baseline benchmarks for taking `Patches` with `PiecewiseSequenceArray`
indices, ahead of the stacked follow-up
#11547, which takes the runs
without expanding them. Landing the benchmarks first gives that change a
recorded baseline to compare against.

## Changes

- Adds `take_piecewise` to `vortex-array/benches/take_patches.rs`. It
takes patches at density 0.1 with ascending runs of contiguous indices,
covering half of a 4096-row array, for run lengths 1, 16 and 256.
- Inputs go through `mark_optimized`, like the existing benchmarks in
this file.

---------

Signed-off-by: Robert Kruszewski <github@robertk.io>
Base automatically changed from rk/patches-piecewise-take-bench to develop November 19, 2026 12:07
@robert3005 robert3005 changed the title perf(patches): take PiecewiseSequenceArray runs without expanding them [kernel] perf(patches): take PiecewiseSequenceArray runs without expanding them Nov 19, 2026
Signed-off-by: Robert Kruszewski <github@robertk.io>
@robert3005 robert3005 changed the title [kernel] perf(patches): take PiecewiseSequenceArray runs without expanding them perf(patches): take PiecewiseSequenceArray runs without expanding them Nov 19, 2026
@robert3005 robert3005 added the quick-review Small, self-contained change that is quick to review label Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/performance A performance improvement quick-review Small, self-contained change that is quick to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant