Skip to content

GH-55741: [C++] Improve ChunkedArray::Slice performance for arrays with many chunks - #55742

Open
Sumdiboii wants to merge 1 commit into
apache:mainfrom
Sumdiboii:perf/cache-chunk-length-in-slice
Open

Sumdiboii wants to merge 1 commit into
apache:mainfrom
Sumdiboii:perf/cache-chunk-length-in-slice

Conversation

@Sumdiboii

@Sumdiboii Sumdiboii commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Rationale for this change

I was looking through ChunkedArray::Slice and noticed that it scans chunks from the beginning to find the chunk containing the requested offset. For arrays with many chunks, this can mean checking many chunks when a slice starts later in the array.

This change uses the existing chunk resolver to find the starting chunk directly, reducing the lookup work for those cases.

What changes are included in this PR?

  • Use ChunkResolver to locate the starting chunk for non-negative slice offsets.
  • Reuse the current chunk and its length while producing the sliced chunks.
  • Add a test covering slices when empty chunks are present.
  • Add a benchmark comparing the previous linear lookup with the resolver-based implementation.

Are these changes tested?

The Release build completed, and all 40 C++ unit-test executables registered in this build passed. The affected arrow-table-test passed all 212 tests, including the new empty-chunk test.

The benchmark compares a benchmark-local reproduction of the previous linear lookup with the current implementation in the same executable. It uses arrays with 4,096 or 16,384 chunks, each containing 8 values, and measures one-element slices at fixed or varying offsets. Each case ran for at least 100 ms per repetition, with nine repetitions and random interleaving. The table shows median CPU time per call.

Chunks Slice start Previous lookup Resolver lookup Speedup
4,096 Middle 1,711 ns 84.4 ns 20.3×
4,096 Near end 3,633 ns 82.1 ns 44.3×
4,096 Varying offsets 1,756 ns 129 ns 13.6×
16,384 Middle 26,974 ns 82.1 ns 328.5×
16,384 Near end 62,546 ns 80.9 ns 772.9×
16,384 Varying offsets 28,681 ns 195 ns 147.2×

Benchmark machine and build: Ubuntu 26.04.1 LTS, kernel 7.0.0-38-generic, 12th Gen Intel Core i5-1235U (12 logical CPUs), 14 GiB RAM, GCC 15.2, Release build.

Slices starting at offset zero showed essentially no difference. These are local microbenchmark results using small, fixed-size chunks; the gains are most evident for later or varying offsets in arrays with many chunks and should not be read as a general speedup for every workload.

The test run covers the C++ unit-test executables enabled in this build, not optional C++ components or other Arrow language implementations.

Are there any user-facing changes?

No public API or intended behavior changes. This is an internal performance change.

Was AI used for this PR?

AI assistance was used to implement and review the code, test, and benchmark, and to draft this description.

PR code and description written by:

  • Human
  • AI

Reviewed before submission by:

  • Human
  • AI
  • Not reviewed

Copilot AI balanced review requested due to automatic review settings November 23, 2026 17:13

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@Sumdiboii
Sumdiboii requested a lite review from Copilot November 23, 2026 17:25

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants