You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "haohuaijin (via GitHub)" <gi...@apache.org> on 2026/07/27 02:45:26 UTC

[PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

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

   # Which issue does this PR close?
   
   - Closes #10422.
   
   # Rationale for this change
   
   Follow up to #10141, which made `RowSelection` optionally backed by a `BooleanBuffer`.
   
   For mask-backed selections, `RowSelection::iter()` lazily materializes an RLE selector cache inside `MaskSelection` (a `OnceLock<Vec<RowSelector>>`). Every path that converted such a selection into `RowSelector`s ignored that cache and called `mask_to_selectors()` again, so a caller that iterates a selection and then consumes it run-length-encodes the whole bitmap twice. For a large selection that is a wasted O(bitmap) pass plus a second selector `Vec` held at the same time.
   
   # What changes are included in this PR?
   
   - `MaskSelection::into_selectors` takes the `OnceLock`'s value when it was populated and otherwise falls back to `mask_to_selectors`. It is used by `RowSelection::into_selectors_vec` (which backs `From<RowSelection>` for both `Vec<RowSelector>` and `VecDeque<RowSelector>`), and by `build_cursor` when lowering a mask-backed selection onto the selector cursor.
   - `MaskSelection::borrowed_selectors` does the same for the borrowing callers in `intersection` and `union`. It returns `Cow::Borrowed` when the cache is populated and otherwise converts into a temporary, rather than populating the cache of a selection the caller still owns.
   - `union` now matches on `(&self.inner, &other.inner)` like `intersection` does, instead of nesting two matches.
   - `mask_to_selectors` no longer has callers outside the `selection` module, so its `pub(crate)` re-export is dropped.
   
   # Are these changes tested?
   
   Yes, four new unit tests in `arrow_reader::selection::boolean`:
   
   - `test_into_selectors_takes_the_iter_cache` compares the `Vec`'s pointer before and after the conversion, asserting the cache is moved out rather than re-encoded.
   - `test_into_selectors_without_cache_still_converts` covers the cold-cache fallback and the `VecDeque` conversion.
   - `test_borrowed_selectors_reuses_cache_without_populating_it` asserts `Cow::Owned` when cold and `Cow::Borrowed` when warm.
   - `test_set_algebra_agrees_whether_or_not_the_cache_is_populated` checks `intersection`/`union` agree in both cache states.
   
   `cargo test -p parquet --all-features` passes.
   
   ## Benchmarks
   
   `row_selector` gains two scenarios over a mask-backed selection of 300k rows, across alternating run lengths and a random mask: `mask_iterate_then_consume` iterates the selection and then converts it, matching what `ParquetAccessPlan::into_overall_row_selection` does; `mask_consume` converts without iterating first, so it measures the cold-cache path.
   
   ```
   cargo bench -p parquet --bench row_selector -- mask_
   ```
   
   | benchmark | main | this PR | change |
   | --- | --- | --- | --- |
   | `mask_iterate_then_consume/run01` | 2.237 ms | 1.202 ms | -46.5% |
   | `mask_iterate_then_consume/run04` | 272.5 µs | 132.4 µs | -51.4% |
   | `mask_iterate_then_consume/run16` | 73.7 µs | 32.5 µs | -55.9% |
   | `mask_iterate_then_consume/run64` | 26.0 µs | 13.6 µs | -47.8% |
   | `mask_iterate_then_consume/random` | 784.1 µs | 404.1 µs | -48.7% |
   
   The cold-cache `mask_consume` cases are unchanged. Their medians over three runs per side land within 1.5% of `main`, which is inside the run-to-run spread `main` shows on its own.
   
   `arrow_reader_clickbench`, `row_selector_boolean_buffer` and the rest of `row_selector` show no change beyond noise: a control run of the same binary against the same baseline drifts by about as much as the comparison run does.
   
   # Are there any user-facing changes?
   
   No. All of the added methods are internal, and the public API and its behavior are unchanged.
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#discussion_r3668204194


##########
parquet/src/arrow/arrow_reader/selection/boolean.rs:
##########
@@ -92,6 +93,22 @@ impl MaskSelection {
             .get_or_init(|| mask_to_selectors(&self.mask))
             .as_slice()
     }
+
+    /// Borrows the cached RLE form, converting into a temporary if not cached.
+    pub(super) fn borrowed_selectors(&self) -> Cow<'_, [RowSelector]> {

Review Comment:
   The fact it is called `borrowed_selectors` but may compute / allocate a temporary was confusing to me
   
   Shouldn't this also set the  `self.selectors` cache if it wasn't already set? 
   
   Otherwise calling this twice in a row will recompute the selectors



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "hhhizzz (via GitHub)" <gi...@apache.org>.
hhhizzz commented on PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#issuecomment-5092591209

   > Thanks. I reran the comparison three times on Apple M4; the results are attached. `run64` remained between approximately -0.6% and +2.5%. `run01` showed a larger regression in one run, but it was not reproduced in the other two. Since the cold path still uses the same `mask_to_selectors` implementation, the variation may be related to system noise, CPU frequency changes, or compiler code-layout differences.
   
   Thanks for checking this on Mac. I profiled the regression on an AMD EPYC 9254 (Zen 4) and reran every input as a separately compiled single-case benchmark.
   
   With three alternating rounds:
   
   - `mask_iterate_then_consume`: all 9 cases improved by 49%–86%.
   - Cold `mask_consume`: no repeatable regression; run32/64/96/128 improved by 2%–7%, while the others were effectively unchanged.
   
   The original run128 regression appears to be an x86_64 code-layout/alignment artifact. `mask_to_selectors` has identical machine code and retired instruction counts, but its address relative to a 32-byte boundary changes when the benchmark case list changes. Changing the layout also flips the performance result.
   
   So I don’t think the previously reported cold-path regression is caused by this PR or should block it. The cold microbenchmark is simply quite sensitive to binary layout on this Zen 4 machine.
   
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on code in PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#discussion_r3672883874


##########
parquet/src/arrow/arrow_reader/selection/boolean.rs:
##########
@@ -92,6 +93,22 @@ impl MaskSelection {
             .get_or_init(|| mask_to_selectors(&self.mask))
             .as_slice()
     }
+
+    /// Borrows the cached RLE form, converting into a temporary if not cached.
+    pub(super) fn borrowed_selectors(&self) -> Cow<'_, [RowSelector]> {

Review Comment:
   my view is keep the `borrowed_selectors` do not set the `self.selectors` cache.
   
   the [`borrowed_selectors`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/boolean.rs#L98-L104) is an internal helper, and its only callers are the mixed-representation paths in [`intersection` and `union`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/mod.rs#L480-L516). and in current datafusion, the relevant call path is:
   
   1. [`prune_plan_with_page_index_and_metrics`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/page_filter.rs#L318-L341)
   2. [`ParquetAccessPlan::scan_selection`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L389-L397)
   3. [`existing_selection.intersection(&selection)`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L394-L395)
   
   After the intersection, the existing mask is immediately replaced with the new selection, so a newly populated cache would not be reused in this path. 
   
   so, keeping the conversion temporary on a cache miss therefore seems more suitable for the current usage.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "hhhizzz (via GitHub)" <gi...@apache.org>.
hhhizzz commented on PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#issuecomment-5088149777

   Thanks for working on this optimization. I independently reproduced the substantial warm-cache improvement, and the cache-reuse approach looks effective for the intended `iterate`-then-consume path. 🚀
   
   I did, however, find a clear and reproducible regression in the cold-cache `mask_consume/run64` case: the PR is approximately **11.4% slower than the base** on my test machine.
   
   The absolute difference is small—about **1.6 µs per conversion of a 300k-row mask**—so this may not be a serious real-world regression, and it does not invalidate the main improvement. However, the result is stable and contradicts the PR's statement that all cold-cache cases remain within 1.5% of `main`. I think it is worth understanding the cause before concluding that the cold path is unchanged.
   
   Could you please try reproducing this case in your environment?
   
   # Details
   
   ### Reproduction setup
   
   - base: `8e7043bf937b60e3be8586ceb3cd00349b989e1e`
   - PR head: `20eb12415e62f86cf31883cc637c09ed304a8896`
   - x86_64 Linux
   - Rust 1.96.1
   - CPU pinned to one core
   - separate Cargo target directories for base and head
   - copied only the PR's `parquet/benches/row_selector.rs` to the base worktree, so both sides used the same benchmark harness
   - no implementation code was copied
   - alternating base/head execution order
   - no Criterion sample-time warnings
   
   First, I ran the complete `mask_` group three times per side:
   
   ```bash
   cargo bench -p parquet --bench row_selector -- mask_
   ```
   
   Criterion settings:
   
   ```text
   warm-up time: 1s
   measurement time: 2s
   sample size: 20
   ```
   
   The cold-cache geometric means were:
   
   | benchmark | base | PR | change |
   | --- | ---: | ---: | ---: |
   | `mask_consume/run01` | 638.630 µs | 639.072 µs | +0.07% |
   | `mask_consume/run04` | 167.478 µs | 167.519 µs | +0.02% |
   | `mask_consume/run16` | 48.721 µs | 48.971 µs | +0.51% |
   | `mask_consume/run64` | 14.391 µs | 16.071 µs | **+11.67%** |
   | `mask_consume/random` | 288.669 µs | 289.050 µs | +0.13% |
   
   I then isolated `mask_consume/run64` and ran five alternating repetitions per side with a longer measurement time:
   
   ```bash
   cargo bench -p parquet --bench row_selector -- 'mask_consume/run64'
   ```
   
   Focused Criterion settings:
   
   ```text
   warm-up time: 1s
   measurement time: 3s
   sample size: 30
   ```
   
   Focused result:
   
   - base geometric mean: **14.427 µs**
   - PR geometric mean: **16.070 µs**
   - change: **+11.39%**
   
   The values were stable across all five repetitions. As a small diagnostic, adding `#[inline]` to `MaskSelection::into_selectors` did not remove the regression, so it does not appear to be caused solely by an additional non-inlined function call.
   
   The main warm-cache improvement was reproduced and remains substantial. My concern is specifically the unexpected cold `run64` behavior. It may be useful to test neighboring run lengths such as 32, 48, 96, and 128 to determine whether this is related to vector capacity, allocation behavior, or another boundary effect.
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on code in PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#discussion_r3672883874


##########
parquet/src/arrow/arrow_reader/selection/boolean.rs:
##########
@@ -92,6 +93,22 @@ impl MaskSelection {
             .get_or_init(|| mask_to_selectors(&self.mask))
             .as_slice()
     }
+
+    /// Borrows the cached RLE form, converting into a temporary if not cached.
+    pub(super) fn borrowed_selectors(&self) -> Cow<'_, [RowSelector]> {

Review Comment:
   my option is keep the `borrowed_selectors` do not set the `self.selectors` cache.
   
   the first point is the [`borrowed_selectors`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/boolean.rs#L98-L104) is an internal helper, and its only callers are the mixed-representation paths in [`intersection` and `union`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/mod.rs#L480-L516). This allows it to reuse the cache when one already exists without necessarily populating it on a cache miss.
   
   another is current in datafusion, the relevant call path is:
   
   1. [`prune_plan_with_page_index_and_metrics`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/page_filter.rs#L318-L341)
   2. [`ParquetAccessPlan::scan_selection`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L389-L397)
   3. [`existing_selection.intersection(&selection)`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L394-L395)
   
   After the intersection, the existing mask is immediately replaced with the new selection, so a newly populated cache would not be reused in this path. 
   
   so, keeping the conversion temporary on a cache miss therefore seems more suitable for the current usage.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#issuecomment-5089491670

   Thanks. I reran the comparison three times on Apple M4; the results are attached. run64 remained between approximately -0.6% and +2.5%. run01 showed a larger regression in one run, but it was not reproduced in the other two. Since the cold path still uses the same mask_to_selectors implementation, the variation may be related to system noise, CPU frequency changes, or compiler code-layout differences.
   
   
   <img width="820" height="1015" alt="image" src="https://github.com/user-attachments/assets/fb6eb76b-3338-4f02-997e-d035077ca5fb" />
   


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on code in PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#discussion_r3672883874


##########
parquet/src/arrow/arrow_reader/selection/boolean.rs:
##########
@@ -92,6 +93,22 @@ impl MaskSelection {
             .get_or_init(|| mask_to_selectors(&self.mask))
             .as_slice()
     }
+
+    /// Borrows the cached RLE form, converting into a temporary if not cached.
+    pub(super) fn borrowed_selectors(&self) -> Cow<'_, [RowSelector]> {

Review Comment:
   my view is keep the `borrowed_selectors` do not set the `self.selectors` cache.
   
   the [`borrowed_selectors`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/boolean.rs#L98-L104) is an internal helper, and its only callers are the mixed-representation paths in [`intersection` and `union`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/mod.rs#L480-L516). and in current datafusion, the relevant call path is:
   
   1. [`prune_plan_with_page_index_and_metrics`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/page_filter.rs#L318-L341)
   2. [`ParquetAccessPlan::scan_selection`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L389-L397)
   3. [`existing_selection.intersection(&selection)`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L394-L395)
   
   After the intersection, the existing mask is immediately replaced with the new selection, so the cache will not be used.
   
   so, keeping the conversion temporary on a cache miss therefore seems more suitable for the current usage.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on code in PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#discussion_r3672883874


##########
parquet/src/arrow/arrow_reader/selection/boolean.rs:
##########
@@ -92,6 +93,22 @@ impl MaskSelection {
             .get_or_init(|| mask_to_selectors(&self.mask))
             .as_slice()
     }
+
+    /// Borrows the cached RLE form, converting into a temporary if not cached.
+    pub(super) fn borrowed_selectors(&self) -> Cow<'_, [RowSelector]> {

Review Comment:
   my view is keep the `borrowed_selectors` do not set the `self.selectors` cache.
   
   the first point is the [`borrowed_selectors`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/boolean.rs#L98-L104) is an internal helper, and its only callers are the mixed-representation paths in [`intersection` and `union`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/mod.rs#L480-L516). and in current datafusion, the relevant call path is:
   
   1. [`prune_plan_with_page_index_and_metrics`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/page_filter.rs#L318-L341)
   2. [`ParquetAccessPlan::scan_selection`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L389-L397)
   3. [`existing_selection.intersection(&selection)`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L394-L395)
   
   After the intersection, the existing mask is immediately replaced with the new selection, so a newly populated cache would not be reused in this path. 
   
   so, keeping the conversion temporary on a cache miss therefore seems more suitable for the current usage.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#issuecomment-5087255612

   cc @alamb @hhhizzz 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#issuecomment-5169705990

   Thanks again @hhhizzz and @haohuaijin 


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "hhhizzz (via GitHub)" <gi...@apache.org>.
hhhizzz commented on PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#issuecomment-5087712020

   > cc @alamb @hhhizzz
   
   I'll take a look later today.


-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on code in PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#discussion_r3672883874


##########
parquet/src/arrow/arrow_reader/selection/boolean.rs:
##########
@@ -92,6 +93,22 @@ impl MaskSelection {
             .get_or_init(|| mask_to_selectors(&self.mask))
             .as_slice()
     }
+
+    /// Borrows the cached RLE form, converting into a temporary if not cached.
+    pub(super) fn borrowed_selectors(&self) -> Cow<'_, [RowSelector]> {

Review Comment:
   my option is keep the `borrowed_selectors` do not set the `self.selectors` cache.
   
   the first point is the [`borrowed_selectors`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/boolean.rs#L98-L104) is an internal helper, and its only callers are the mixed-representation paths in [`intersection` and `union`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/mod.rs#L480-L516). and in current datafusion, the relevant call path is:
   
   1. [`prune_plan_with_page_index_and_metrics`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/page_filter.rs#L318-L341)
   2. [`ParquetAccessPlan::scan_selection`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L389-L397)
   3. [`existing_selection.intersection(&selection)`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L394-L395)
   
   After the intersection, the existing mask is immediately replaced with the new selection, so a newly populated cache would not be reused in this path. 
   
   so, keeping the conversion temporary on a cache miss therefore seems more suitable for the current usage.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] perf(parquet): reuse `MaskSelection`'s cached selectors when converting to selectors [arrow-rs]

Posted by "haohuaijin (via GitHub)" <gi...@apache.org>.
haohuaijin commented on code in PR #10443:
URL: https://github.com/apache/arrow-rs/pull/10443#discussion_r3672883874


##########
parquet/src/arrow/arrow_reader/selection/boolean.rs:
##########
@@ -92,6 +93,22 @@ impl MaskSelection {
             .get_or_init(|| mask_to_selectors(&self.mask))
             .as_slice()
     }
+
+    /// Borrows the cached RLE form, converting into a temporary if not cached.
+    pub(super) fn borrowed_selectors(&self) -> Cow<'_, [RowSelector]> {

Review Comment:
   mabye we can keep the `borrowed_selectors` do not set the `self.selectors` cache for now. and do it later if we really need. the [`borrowed_selectors`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/boolean.rs#L98-L104) is an internal helper, and its only callers are the mixed-representation paths in [`intersection` and `union`](https://github.com/apache/arrow-rs/blob/e5f4ec70fefc0db102c7a7ef77eed69d806a300e/parquet/src/arrow/arrow_reader/selection/mod.rs#L480-L516). and in current datafusion, the relevant call path is:
   
   1. [`prune_plan_with_page_index_and_metrics`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/page_filter.rs#L318-L341)
   2. [`ParquetAccessPlan::scan_selection`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L389-L397)
   3. [`existing_selection.intersection(&selection)`](https://github.com/apache/datafusion/blob/ef94a85b85bfc19042cad8c732ad1d78f07b34a5/datafusion/datasource-parquet/src/access_plan.rs#L394-L395)
   
   After the intersection, the existing mask is immediately replaced with the new selection, so the cache will not be used.
   
   so, keeping the conversion temporary on a cache miss therefore seems more suitable for the current usage.



-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org