Optimize RowNumberReader to be 8x faster#9680
Open
Samyak2 wants to merge 1 commit intoapache:mainfrom
Open
Conversation
- 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`).
I do not have micro-benchmark numbers for this change, but I have noticed a 3x improvement in execution time for an internal query.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
We internally found
RowNumberReaderto be a hot path in some of our queries. Flamegraphs showed ~70% of the cpu time taken by methods inRowNumberReader.These can be made an order of magnitude faster (benchmarks below).
What changes are included in this PR?
read_recordswas previously linear in terms of number of rows read.skip_recordsconsume_batchis still linear in terms of rows, but it is faster since it can pre-allocate the output vec.Flatteniter would have prevented it pre-allocating (it's not anExactSizeIterator).Are these changes tested?
RowNumberReaderto be pub, so I've not included them hereBefore:
After:
Ranging from 8.6x to 8.9x faster!
Are there any user-facing changes?
No