Sumdiboii opened a new pull request, #55742: URL: https://github.com/apache/arrow/pull/55742
### 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:** - [x] Human - [x] AI **Reviewed before submission by:** - [x] Human - [x] AI - [ ] Not reviewed * GitHub Issue: Fixes #55741 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
