adriangb opened a new pull request, #12487:
URL: https://github.com/apache/arrow-rs/pull/12487

   # Which issue does this PR close?
   
   - Part of https://github.com/apache/arrow-rs/issues/11234.
   - Split out of https://github.com/apache/arrow-rs/pull/11238 to make that PR 
smaller.
   
   # Rationale for this change
   
   `RowSelection::scan_ranges` visits each page of a column chunk, also the 
pages that a skip covers. `ColumnFetch::new` then visits each page again to map 
the byte ranges to page indexes. Both are O(pages) for each call.
   
   One call per row group is cheap. The batch-granular push decoder of 
https://github.com/apache/arrow-rs/pull/11238 makes one call per batch, so a 
row group costs O(batches × pages) for each column. A profile of that PR showed 
`scan_ranges` as the largest cost.
   
   # What changes are included in this PR?
   
   ```diff
    scan_ranges_from_selectors
      for each selector
        if skip
   -      visit each page that the skip covers
   +      partition_point: move to the page that holds the end of the skip
        if select
          add each page that the selected rows touch
   
    ColumnFetch::new
      for each range
   -    position in all page locations
   +    binary search, from the page of the previous range
   ```
   
   One behavior difference: a selector that selects 0 rows no longer adds the 
page at its position. The readers ignore such a selector.
   
   # Are these changes tested?
   
   Yes. `scan_ranges_from_selectors_matches_a_scan_of_all_pages` is a 
differential test with a seeded random generator. It compares the new lookup 
with a linear scan of all pages for random page layouts and selections. The 
existing selection tests pass.
   
   Benchmarks (`benches/push_decoder.rs`, GCP `c4a-standard-16`, mean of two 
rounds), with the `decode` group from 
https://github.com/apache/arrow-rs/pull/12486:
   
   | Benchmark | Before | After | Change |
   |---|---|---|---|
   | `decode/batch/100pages_10batch` (needs 
https://github.com/apache/arrow-rs/pull/11238) | 1038.8 µs | 904.3 µs | -13% |
   | `decode/batch/10pages_100batch` (needs 
https://github.com/apache/arrow-rs/pull/11238) | 93.2 µs | 94.1 µs | +1% |
   | `decode/row_group/100pages_10batch` | 488.5 µs | 494.0 µs | +1% |
   | `decode/row_group/10pages_100batch` | 60.25 µs | 60.21 µs | 0% |
   | `1buf/100000ranges` | 65.75 ms | 66.50 ms | +1% |
   | `Nbuf/100000ranges` | 78.62 ms | 80.67 ms | +3% |
   
   - The gain is in the case with many small pages and one call per batch. That 
case exists only with https://github.com/apache/arrow-rs/pull/11238.
   - On `main` the change is inside the noise of the run (two rounds of one 
build differ by up to 3%). `1buf` and `Nbuf` do not call the changed code, so 
their rows show that noise.
   - No input got slower beyond the noise. The binary search has a cost when a 
selection has no skips, and `decode/row_group` (no selection) does not measure 
it.
   
   # Are there any significant user-facing changes?
   
   One small change in the output of a public method. 
`RowSelection::scan_ranges` no longer returns the range of a page for a 
selector that selects 0 rows. A `RowSelection` built from selectors has no such 
selector, because `FromIterator<RowSelector>` removes them. There is no API 
change.
   
   # AI usage disclosure
   
   Claude Code wrote the code, the tests and this description, under my 
direction.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
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]

Reply via email to