Repository navigation
Skip building the filter output null buffer when no selected row is null - #11257
bharadwaj-pendyala wants to merge 7 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
The rows without nulls ( The cases this PR is for are the only-valid ones from #11256, which isn't merged yet, so this run can't show them. |
|
Thanks @bharadwaj-pendyala -- I merged #11256 and will rerun the benchmarks |
This comment has been minimized.
This comment has been minimized.
1 similar comment
This comment has been minimized.
This comment has been minimized.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing perf/filter-skip-all-valid-nulls (151769d) to 8c230e6 (merge-base) diff Run configurationrun benchmark filter_kernelsCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
🤖 Arrow criterion benchmark completed (GKE) | trigger Instance: Comparing perf/filter-skip-all-valid-nulls (151769d) to 8c230e6 (merge-base) diff Run configurationrun benchmark filter_kernelsCPU Details (lscpu)Details
Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
Both reruns agree on the only-valid rows: 2.6x at kept 1/4, 3.1-3.2x at 1023/2048, 1.8x at 1/2048. The nulls-at-end dense row came out worse than my PR description says, though. It went from 5.5-5.6 µs to 6.4 µs (14% and 18%), against the ~7% I measured on my M1. That row is the worst case on purpose, with the one selected null in the last word, so the scan reads both bitmaps in full before |
…pache#11399) - related to apache#11257 i wanted to run all the benchmarks which exhibit affected `filter_nulls` path, but looks like there were some benchmarks that exhibited that path but didnt actually have `NULLS` in the name so its harder to ensure we get a comprehensive run fix generated by codex & reviewed by me
|
run benchmark filter_kernels |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Benchmark completed (GKE) | trigger Target: filter_kernels Comparing perf/filter-skip-all-valid-nulls (3770a3c) to e189ba8 (merge-base) diff Run configurationrun benchmark filter_kernels
env:
BENCH_FILTER: 'NULL'
shards: 1
DetailsPer-runner informationfilter_kernels — shard 1/1Node: gk3-benchmark-cluster-nap-zev6bi7t-2df76d26-zqlk Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench filter_kernelsCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
|
run benchmark filter_kernels |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Benchmark completed (GKE) | trigger Target: filter_kernels Comparing perf/filter-skip-all-valid-nulls (3770a3c) to e189ba8 (merge-base) diff Run configurationrun benchmark filter_kernels
env:
BENCH_FILTER: 'NULL'
shards: 1
DetailsPer-runner informationfilter_kernels — shard 1/1Node: gk3-benchmark-cluster-nap-qrixxqdb-3ecd588e-tflj Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench filter_kernelsCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
Jefffrey
left a comment
There was a problem hiding this comment.
the improvement makes sense to me and the benchmark improvement looks good; i guess with adding this logic its inevitable that there are tiny regressions since we are adding extra instructions, so not sure if they are significant enough to block the PR (would be glad to have a second opinion)
one note is that the test code seems a bit unintuitive in how it constructs its test cases, i feel they can be simplified and/or explained better
| #[should_panic(expected = "nulls.len() >= len")] | ||
| fn test_filter_nulls_shorter_than_filter() { | ||
| let nulls = NullBuffer::from_iter((0..8).map(|i| i != 1)); | ||
| let predicate = BooleanArray::from_iter((0..9).map(|i| Some(i == 0))); |
There was a problem hiding this comment.
instead of constructing these from a mapped iter we can just construct them directly from vecs of bools
|
|
||
| // Sliced at offset 1 so the null bits sit off a byte boundary, with a | ||
| // partial trailing word. Rows 0 and 129 are null. | ||
| fn nullable_slice(null_every: i32) -> Int32Array { |
There was a problem hiding this comment.
the numbers chosen here seem odd and out of place; why choose a big value like 131? and why are rows 0 and 129 guaranteed to be null here, wouldnt that depend on the input?
|
|
||
| #[test] | ||
| fn test_filter_nulls_selecting_only_valid_rows() { | ||
| // Every 43rd row null puts the dense filter above the slices threshold |
There was a problem hiding this comment.
which slices threshold are we talking about here?
| let nulls = values.nulls().unwrap(); | ||
| let masks = filter_masks(|i| nulls.is_valid(i)) | ||
| .into_iter() | ||
| .chain(filter_masks(|i| i == 128)); |
There was a problem hiding this comment.
why is this chain necessary, what does it achieve in the test?
|
Reworked the 287ff06 moves the |
|
@Rich-T-kid, could you take a look? CI is green on 77ae0c5, and it still merges cleanly on top of the Boolean filter changes from #11918. |
|
run benchmark filter_kernels |
This comment was marked as duplicate.
This comment was marked as duplicate.
|
🤖 Benchmark completed (GKE) | trigger Target: filter_kernels Comparing perf/filter-skip-all-valid-nulls (2d7a8d2) to 6ec6d46 (merge-base) diff Run configurationrun benchmark filter_kernels
env:
BENCH_FILTER: 'NULL'
shards: 1
DetailsPer-runner informationfilter_kernels — shard 1/1Node: gk3-benchmark-cluster-nap-mu2kt4to-72b5594a-nx8c Instance: c4a-highmem-16 (12 vCPU / 65 GiB) uname: BENCH_COMMAND: cargo bench --features=arrow,async,test_common,experimental,object_store --bench filter_kernelsCPU Details (lscpu)Resource Usagebase (merge-base)
branch
File an issue against this benchmark runner |
Which issue does this PR close?
filter: Avoid constructing filter output validity when every selected value is valid #11200.Rationale for this change
When the input has nulls,
FilterPredicate::filter_nullsalways filters the validity into a new buffer and counts it, then drops the buffer if the count comes out zero. A filter that keeps no null rows, likex IS NOT NULL AND ..., pays for a bitmap it never uses.What changes are included in this PR?
filter_nullsnow asksselects_nullfirst and returnsNonestraight away when no selected row is null.selects_nullzips the 64-bit words of the mask and the validity and stops at the first word wherekeep & !validis non-zero. It doesn't allocate, and it takes the offsets of both buffers into account. For an optimizedIndicespredicate below one selected row per word, it probes those indices instead. That's the crossoverfilter_bitsalready uses forsparse_indices. Without it, a 1/2048 filter scans all 1024 words to check 32 rows, and above that crossover the word scan wins. An early version probed indices for everyIndicespredicate and took 98 µs at kept 1/4 instead of 43 µs.filter_nullsreturns early for theNoneandAllstrategies before it callsselects_null, so those two don't pay for the scan. It checks that the null buffer covers the filter before the scan too. Without that check, the sparse index path would read only the selected rows and quietly returnNone.Are these changes tested?
Yes, in
arrow-select/src/filter.rs:test_filter_nulls_selecting_only_valid_rowsassertsselects_nullis false and the filtered array has no null buffer.test_filter_nulls_selecting_one_nullasserts it's true when the only selected null is row 0 or 64 (full words) or row 199 (the partial last word).Both run the lazy and optimized predicates, sliced and unsliced masks, over values sliced at offset 1. The masks land on both sides of
FILTER_SLICES_SELECTIVITY_THRESHOLD, plus one sparse enough for the index probe.test_filter_nulls_too_largecovers the length check on that sparse path.Each of these edits turns at least one test red: dropping the trailing partial word, ignoring the null buffer's offset, ignoring the mask's offset, having the index probe return false, having
selects_nullreturn true (today's behaviour), and removing the assert.cargo test -p arrow-selectis 456 passed, 0 failed.cargo test -p parquet --features arrow --lib arrow::arrow_readeris 158 passed.cargo fmt --all -- --checkandcargo clippy -p arrow-select --all-targets --all-features -- -D warningsare clean.Benchmarks are the cases from #11256. I built two release binaries, main at
fa337f8and this branch, and ran them alternately. M1 laptop, criterion median, 3 rounds unless noted:The last two nulls-at-end rows are the cost. When the only selected null sits in the last word, the scan reads both bitmaps once before
filter_bitsreads them again, which comes to about 7% on the dense case on my M1. In the two GKE reruns on this PR (Neoverse-V2) it's 14-18%, 5.5-5.6 µs to 6.4 µs. With random nulls the scan stops in the first word, and the existing cases don't move beyond noise. Main swings a lot on the only-valid rows between runs, and this branch doesn't, so the low end of the main range is the fair comparison.Are there any user-facing changes?
No API change.
filter_nullsreturns the same thing as before. A null buffer shorter than the filter that has any nulls still panics withassertion failed: nulls.len() >= self.filter.len(), same as before.AI usage
Claude wrote the change, tests and benchmarks. Codex reviewed the diff adversarially twice before the push. The first pass flagged the index probe running for dense
Indicespredicates and the missing length check. The second pass flagged that the only-valid test would pass even ifselects_nullalways returned true. I fixed all three and ran the edits above to check the tests catch them. I also measured every number here myself.