-
Notifications
You must be signed in to change notification settings - Fork 0
(refac): return BitVector for performance
#15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Add unsafe_acquire!(pool, Bit, n) that returns a real BitVector with
shared chunks, providing ~140x performance improvement for native
BitVector operations like count(), sum(), and bitwise ops.
Changes:
- Add get_bitvector_wrapper! with N-way cache for wrapper reuse
- Replace _throw_bit_unsafe_error with actual implementation
- Support N-D via reshape(BitVector, dims) returning BitArray{N}
- Add pool_stats and show methods for BitTypedPool
- Fix pool display when BitTypedPool has content
The wrapper BitVector shares the pooled BitVector's chunks field,
preserving SIMD optimizations while reusing pool memory.
Separate BitArray-specific code from acquire.jl into bitarray.jl
for improved maintainability and code organization.
Moved to src/bitarray.jl:
- allocate_vector(::BitTypedPool, n) dispatch
- Base.zero/one(::Type{Bit}) overloads
- get_bitvector_wrapper! (SIMD-optimized chunks sharing)
- _unsafe_acquire_impl! for Bit type
- DisabledPool fallbacks for Bit type
No functional changes - all tests pass with same coverage.
Both acquire! and unsafe_acquire! now return BitVector for Bit type, eliminating the need for users to choose between APIs to get optimal performance. The _acquire_impl! for Bit now delegates to _unsafe_acquire_impl!, ensuring ~140x faster SIMD operations (count, sum, bitwise) are always used. Also fixes BitVector wrapper sizing to use exact length (!=) instead of minimum length (<), ensuring fill!/count! iterate only over relevant chunks.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #15 +/- ##
==========================================
+ Coverage 96.45% 96.88% +0.42%
==========================================
Files 8 9 +1
Lines 1072 1155 +83
==========================================
+ Hits 1034 1119 +85
+ Misses 38 36 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…rmance optimization
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request refactors the BitArray acquisition API to unify the return type to always be BitVector (instead of SubArray{Bool}) for SIMD-optimized performance. The PR includes a breaking change where acquire!(pool, Bit, n) now returns BitVector instead of SubArray{Bool}, providing ~10-100x performance improvements for operations like count(), sum(), and bitwise operations.
Changes:
- Unified Bit type API: both
acquire!andunsafe_acquire!now returnBitVectorfor SIMD performance - Extracted BitArray-specific logic to a new dedicated
bitarray.jlfile for better code organization - Updated documentation for
BitandBitTypedPooltypes to reflect the new behavior - Added comprehensive tests validating the new BitVector return types
- Minor workflow improvement to enable TagBot changelog generation
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
src/bitarray.jl |
New file containing BitArray-specific acquisition logic with get_bitvector_wrapper! function that creates BitVector shells sharing chunks with pooled storage |
src/acquire.jl |
Removed BitArray-specific code (moved to bitarray.jl), including error throwing for unsafe_acquire! and Bit type dispatch |
src/types.jl |
Updated documentation for Bit and BitTypedPool to reflect unified BitVector API and corrected field descriptions for N-D caching |
src/utils.jl |
Added pool_stats and Base.show implementations for BitTypedPool |
src/AdaptiveArrayPools.jl |
Added include for new bitarray.jl file |
test/test_bitarray.jl |
Updated tests to verify BitVector return types (instead of SubArray), added new tests for unsafe_acquire! with Bit type |
.github/workflows/TagBot.yml |
Removed changelog: false to enable automatic changelog generation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…tatistics and testing
…nd BitMatrix acquisition
… usage and performance optimizations
…y reuse
- Replace get_bitvector_wrapper! with get_bitarray! supporting proper N-D caching
- Exploit BitArray.dims mutability for same-ndims reuse (0 allocation)
- Add isa type check before equality to prevent Vector{Any} boxing
- Remove unused views/view_lengths fields from BitTypedPool
- Split empty! into separate BitTypedPool and TypedPool methods
- Add test verifying zero-allocation on cached BitArray retrieval
Summary
Unify Bit type API to always return
BitVectorfor SIMD-optimized performance.acquire!(pool, Bit, n)now returnsBitVectorinstead ofSubArray{Bool}.Why this matters:
BitVectoroperations likecount(),sum(), and bitwise ops are 10x~100x faster thanSubArrayequivalents due to SIMD-optimized chunk algorithms.Migration: No code changes needed for typical usage. Only affects code that explicitly type-checks for
SubArray.Changes
acquire!andunsafe_acquire!returnBitVectorforBittypecount())prod()withsafe_prod()for overflow protectionbitarray.jlfile