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

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements and this helps us generate change logs for our releases. You can 
link an issue to this PR using the GitHub syntax.
   -->
   
   - Closes None
   
   # Rationale for this change
   
   <!--
   Why are you proposing this change? If this is already explained clearly in 
the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your 
changes and offer better suggestions for fixes.
   -->
   
   We internally found `RowNumberReader` to be a hot path in some of our 
queries. Flamegraphs showed ~70% of the cpu time taken by methods in 
`RowNumberReader`.
   
   These can be made an order of magnitude faster (benchmarks below).
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is 
sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   - Instead of storing an iterator over individual row numbers, we now store a 
vec of ranges.
       - These ranges are not materialized into a fully array until needed.
   - `read_records` was previously linear in terms of number of rows read.
     - Now it's close to constant since one batch (8192 rows) usually is 
satisfied by one row range (which comes from a row group).
     - Same for `skip_records`
   - `consume_batch` is still linear in terms of rows, but it is faster since 
it can pre-allocate the output vec.
     - Previously, the `Flatten` iter would have prevented it pre-allocating 
(it's not an `ExactSizeIterator`).
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are 
they covered by existing tests)?
   -->
   
   - Yes, added more unit tests
   - I have some benchmarks at https://github.com/Samyak2/arrow-rs/pull/1, but 
they need `RowNumberReader` to be pub, so I've not included them here
   
   Before:
   ```
   Benchmarking row_number_read_consume: Warming up for 3.0000 s
   Warning: Unable to complete 100 samples in 5.0s. You may wish to increase 
target time to 7.0s, enable flat sampling, or reduce sample count to 50.
   row_number_read_consume time:   [1.3915 ms 1.3967 ms 1.4035 ms]
   Found 11 outliers among 100 measurements (11.00%)
     1 (1.00%) low severe
     1 (1.00%) low mild
     5 (5.00%) high mild
     4 (4.00%) high severe
   
   row_number_skip_and_read
                           time:   [716.61 µs 718.14 µs 719.91 µs]
   Found 6 outliers among 100 measurements (6.00%)
     1 (1.00%) low severe
     1 (1.00%) low mild
     3 (3.00%) high mild
     1 (1.00%) high severe
   ```
   
   After:
   ```
   row_number_read_consume time:   [159.00 µs 160.81 µs 162.68 µs]
                           change: [−88.900% −88.721% −88.505%] (p = 0.00 < 
0.05)
                           Performance has improved.
   Found 3 outliers among 100 measurements (3.00%)
     1 (1.00%) low mild
     2 (2.00%) high mild
   
   row_number_skip_and_read
                           time:   [79.057 µs 79.924 µs 80.846 µs]
                           change: [−89.025% −88.865% −88.712%] (p = 0.00 < 
0.05)
                           Performance has improved.
   Found 2 outliers among 100 measurements (2.00%)
     2 (2.00%) high mild
   ```
   
   Ranging from **8.6x to 8.9x faster**!
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be 
updated before approving the PR.
   
   If there are any breaking changes to public APIs, please call them out.
   -->
   
   No


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