IN LIST: add branchless filter for small primitive lists#23014
Draft
geoffreyclaude wants to merge 2 commits into
Draft
IN LIST: add branchless filter for small primitive lists#23014geoffreyclaude wants to merge 2 commits into
geoffreyclaude wants to merge 2 commits into
Conversation
11 tasks
428e3cd to
eae4046
Compare
This was referenced Jun 18, 2026
eae4046 to
3e3651b
Compare
3e3651b to
6a1869f
Compare
bf69ed2 to
e040466
Compare
04ca744 to
f89d3b6
Compare
f89d3b6 to
409b0cb
Compare
95965f5 to
9158a1a
Compare
9158a1a to
8a1184e
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 non-unsigned primitive values, this PR keeps the logical Arrow type explicit and uses the matching unsigned same-width physical representation only inside the branchless filter. For example,
Float16usesUInt16storage,Float32usesUInt32storage, andTimestampNanosecondusesUInt64storage. This preserves bit-pattern equality while keeping construction and probing tied to the original logical type.What changes are included in this PR?
BranchlessFilterfor small primitiveINlists.strategy.rs.Int8->UInt8Int16,Float16->UInt16Int32,Float32,Date32,Time32->UInt32Int64,Float64,Date64,Time64,Timestamp,Duration->UInt64IN/NOT INnull behavior as the rest of the stack.Are these changes tested?
Yes.
cargo fmt --all -- --checkcargo test -p datafusion-physical-expr expressions::in_list --libcargo test -p datafusion-physical-expr --bench in_list_strategy --no-runcargo clippy --all-targets --all-features -- -D warningsAre there any user-facing changes?
No. This is an internal performance optimization only.
Local benchmark snapshot
Built and run with
release-nonlto, filtered to the relevant small primitive-list rows:Filters used:
narrow_integer,primitive/i32/small_list,primitive/i64/small_list,f32/small_list, andtimestamp_ns/small_list.Method: directly compared Criterion's raw sample minima (
min(time / iterations)) fromsample.json. Lower is better; changes within +/-5% are treated as noise.Compared baselines: #23311 -> #23014
Relevant scope: small primitive-list rows.
Summary: 37 relevant rows, 26 faster, 0 slower, 11 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%timestamp_ns/small_list/list=4/match=0%f32/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%timestamp_ns/small_list/list=16/match=50%nulls/primitive/i32/small_list/list=16/match=50%/nulls=50%nulls/primitive/i32/small_list/list=16/match=50%/nulls=20%/NOT_INf32/small_list/list=32/match=50%primitive/i64/small_list/list=16/match=50%Full relevant table (37 rows)
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%narrow_integer/i16/list=64/match=0%narrow_integer/i16/list=64/match=50%narrow_integer/i16/list=256/match=0%narrow_integer/i16/list=256/match=50%narrow_integer/f16/list=4/match=0%narrow_integer/f16/list=4/match=50%narrow_integer/f16/list=64/match=0%narrow_integer/f16/list=64/match=50%narrow_integer/f16/list=256/match=0%narrow_integer/f16/list=256/match=50%nulls/narrow_integer/u8/list=16/match=50%/nulls=20%primitive/i32/small_list/list=4/match=0%primitive/i32/small_list/list=4/match=50%primitive/i32/small_list/list=32/match=0%primitive/i32/small_list/list=32/match=50%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_INnulls/primitive/i32/small_list/list=16/match=50%/nulls=50%primitive/i64/small_list/list=4/match=0%primitive/i64/small_list/list=4/match=50%primitive/i64/small_list/list=16/match=0%primitive/i64/small_list/list=16/match=50%f32/small_list/list=4/match=0%f32/small_list/list=4/match=50%f32/small_list/list=32/match=0%f32/small_list/list=32/match=50%timestamp_ns/small_list/list=4/match=0%timestamp_ns/small_list/list=4/match=50%timestamp_ns/small_list/list=16/match=0%timestamp_ns/small_list/list=16/match=50%