IN LIST: add branchless filter for small primitive lists#23014
Draft
geoffreyclaude wants to merge 4 commits into
Draft
IN LIST: add branchless filter for small primitive lists#23014geoffreyclaude wants to merge 4 commits into
geoffreyclaude wants to merge 4 commits into
Conversation
10 tasks
428e3cd to
eae4046
Compare
This was referenced Jun 18, 2026
eae4046 to
3e3651b
Compare
3e3651b to
6a1869f
Compare
bf69ed2 to
e040466
Compare
a7ef7d4 to
4c92c63
Compare
Introduces zero-copy buffer reinterpretation to allow signed integers and other 1 or 2-byte primitive types (e.g. Float16) to use the high-performance bitmap filters. Triggers for all types with 1-byte or 2-byte width.
Adds a const-generic unrolled comparison chain that avoids CPU branching. Outperforms hash lookups for very small lists. Triggers for primitives when list size <= 32 (4-byte), 16 (8-byte), or 4 (16-byte).
4c92c63 to
ff38ee7
Compare
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?
INperformance with specialized implementations #19390.Rationale for this change
For very small
INlists, building or probing a hash table can be more work than just comparing the input value with each constant.For example, for
x IN (10, 20, 30), the fast path can behave like:Because the list is tiny, those comparisons are cheap. The implementation stores the constants in a fixed-size array and checks them with a compact comparison chain.
“Branchless” here means the comparisons are combined without stopping at the first match. That can be faster for these small fixed-width lists because the CPU gets a predictable sequence of simple operations instead of hash-table setup and probe logic.
Larger primitive lists are left for #23015, where a purpose-built hash lookup becomes the better tradeoff.
For 1-byte and 2-byte primitives, this PR uses branchless only for the short lists where a few direct comparisons can avoid the setup cost of building a bitmap. The cutoffs are intentionally modest: up to 16 values for 1-byte types, and up to 8 values for 2-byte types. Beyond that, the comparison sequence grows quickly and the bitmap path remains the better default.
What changes are included in this PR?
BranchlessFilterfor small primitiveINlists.IN/NOT INnull behavior as the rest of the stack.Are these changes tested?
Yes.
cargo fmt --all --checkcargo test -p datafusion-physical-expr reinterpreted_ --libcargo test -p datafusion-physical-expr in_list_int_types --libcargo test -p datafusion-physical-expr in_list_float64 --libcargo test -p datafusion-physical-expr in_list_decimal --libcargo test -p datafusion-physical-expr test_in_list_from_array_type_combinations --libcargo clippy -p datafusion-physical-expr --all-targets --all-features -- -D warningsAre there any user-facing changes?
No. This is an internal performance optimization only.
Local benchmark snapshot
Benchmark command:
Method: compare adjacent saved baselines using raw Criterion sample minima (
min(time / iters)). Lower is better; changes within +/-5% are treated as noise.Compared baselines: #23013 -> #23014
Relevant scope: small primitive-list rows.
Summary: 27 relevant rows, 24 faster, 0 slower, 3 within +/-5%.
Largest relevant deltas:
timestamp_ns/small_list/list=4/match=50%f32/small_list/list=4/match=50%primitive/i32/small_list/list=4/match=50%primitive/i64/small_list/list=4/match=50%f32/small_list/list=4/match=0%timestamp_ns/small_list/list=4/match=0%primitive/i32/small_list/list=4/match=0%primitive/i64/small_list/list=4/match=0%primitive/i32/small_list/list=16/match=50%/NOT_INnulls/primitive/i32/small_list/list=16/match=50%/nulls=20%nulls/primitive/i32/small_list/list=16/match=50%/nulls=20%/NOT_INtimestamp_ns/small_list/list=16/match=50%nulls/primitive/i32/small_list/list=16/match=50%/nulls=50%f32/small_list/list=32/match=50%primitive/i64/small_list/list=16/match=50%Full relevant table (27 rows)
f32/small_list/list=32/match=0%f32/small_list/list=32/match=50%f32/small_list/list=4/match=0%f32/small_list/list=4/match=50%nulls/primitive/i32/small_list/list=16/match=50%/nulls=20%nulls/primitive/i32/small_list/list=16/match=50%/nulls=20%/NOT_INnulls/primitive/i32/small_list/list=16/match=50%/nulls=50%primitive/i32/small_list/list=16/match=50%/NOT_INprimitive/i32/small_list/list=32/match=0%primitive/i32/small_list/list=32/match=50%primitive/i32/small_list/list=4/match=0%primitive/i32/small_list/list=4/match=50%primitive/i64/small_list/list=16/match=0%primitive/i64/small_list/list=16/match=50%primitive/i64/small_list/list=4/match=0%primitive/i64/small_list/list=4/match=50%timestamp_ns/small_list/list=16/match=0%timestamp_ns/small_list/list=16/match=50%timestamp_ns/small_list/list=4/match=0%timestamp_ns/small_list/list=4/match=50%narrow_integer/u8/list=4/match=0%narrow_integer/u8/list=4/match=50%narrow_integer/u8/list=16/match=0%narrow_integer/u8/list=16/match=50%narrow_integer/i16/list=4/match=0%narrow_integer/i16/list=4/match=50%nulls/narrow_integer/u8/list=16/match=50%/nulls=20%