Repository navigation
Conversation
…mpaction Replace per-element GetBit/SetBit branching loops in PrimitiveFilterImpl::Exec with 64-bit word-level filtering via BitmapWordReader<uint64_t>: - Perform branchless compaction for fixed-width 1/2/4/8/16-byte primitive values at medium selectivity whenever out_position + 64 <= out_length, falling back to sparse countr_zero iteration for low selectivity (popcount <= 8) and the final tail blocks. - Keep VisitSetBitRunsVoid for very high selectivity (>93.75%) with no nulls and coalesce consecutive all-selected 64-bit words into single CopyBitmap + memcpy segments. - Compact output validity bitmaps and boolean values in 64-bit registers via CompactBitmapWord / WriteBits64, and pre-fill out_is_valid once when output has no nulls.
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.
Rationale for this change
PrimitiveFilterImpl::Exec()spends most of its time on branch mispredictions and bit-at-a-time manipulation at medium selectivity (~50%) and whenever nulls are present:VisitSetBitRunsVoidemits very short 1 to 2 element runs at ~50% selectivity, leading to tens of thousands of tinymemcpycalls and mispredicted run loops.GetBitbranches and per-bit read-modify-writeSetBitcalls.What changes are included in this PR?
PrimitiveFilterImplviaBitmapWordReader<uint64_t>.CompactTypedBlock64) for 1, 2, 4, 8, and 16-byte fixed-width primitives when a 64-bit word has more than 8 set bits andout_position_ + 64 <= out_length_(guaranteeing all speculative writes stay within the allocated output buffer, and any trailing speculative slot is overwritten by subsequent selected elements). Sparse words (popcount <= 8), other byte widths, and final tail blocks usestd::countr_zeroiteration.VisitSetBitRunsVoidfor the no-nulls path when selectivity exceeds 93.75% (out_length_ > values_length_ - (values_length_ >> 4)) so near-100% bulk copies stay untouched, and coalesce consecutive all-1 words in the word loop into bulkCopyBitmapandmemcpysegments.CompactBitmapWordand exact byte-boundedWriteBits64), pre-fillout_is_valid_once up front whenDROPproduces zero output nulls, and remove the unusedDropNullCounter.Benchmarks on Linux x86_64 (AMD Ryzen 9 9950X3D, GCC 13.3.0,
RelWithDebInfo, pinned to one core, median of 5 repetitions, back-to-back A/B againstmain):1048576bytes)FilterInt64FilterWithNulls/1048576/1(5% mask nulls, 50% sel)FilterInt64FilterNoNulls/1048576/4(0.1% data nulls, 50% sel)FilterInt64FilterWithNulls/1048576/4(0.1% data, 5% mask, 50% sel)FilterInt64FilterNoNulls/1048576/7(1% data nulls, 50% sel)FilterInt64FilterWithNulls/1048576/7(1% data, 5% mask, 50% sel)FilterInt64FilterWithNulls/1048576/10(10% data, 5% mask, 50% sel)FilterInt64FilterNoNulls/1048576/10(10% data nulls, 50% sel)FilterInt64FilterNoNulls/1048576/1(0% nulls, 50% sel)FilterInt64FilterWithNulls/1048576/2(5% mask nulls, 1% sel)FilterInt64FilterWithNulls/1048576/0(5% mask nulls, 99.9% sel)FilterInt64FilterNoNulls/1048576/2(0% nulls, 1% sel)FilterInt64FilterNoNulls/1048576/0(0% nulls, 99.9% sel)FilterFixedSizeBinaryshows similar gains at 50% selectivity with mask nulls (9.19x on 8-byte values and 4.85x on 9-byte arbitrary-width values).Are these changes tested?
Yes. Added a filter test in
vector_selection_test.cccoveringboolean,int8,int16,int32,int64,decimal128,decimal256, andfixed_size_binary(3)across boundary lengths up to 1025, sliced data and sliced filter masks, data and filter nulls, selectivities from 0% to 100%, and bothDROPandEMIT_NULL, comparing every output element and null bit against a scalar reference and checkingValidateFull(). Verified locally with the vector selection unit test suite,clangwarning checks, andpre-commitC++ format/lint checks on Linux x86_64 (relying on CI for ASAN/UBSAN, ARM64, and MSVC).Are there any user-facing changes?
No.
Was AI used for this PR?
In accordance to the AI generation guidelines, please disclose below whether and how AI was used in this PR.
AI coding assistance was used to draft the word-level compaction helpers and edge-case tests; I reviewed the bounds invariants, code, and benchmarks before opening the PR.
PR code and description written by:
Reviewed before submission by: