Merged
Conversation
- Add BitTypedPool struct extending AbstractTypedPool{Bool, BitVector}
- Add `bits` field to AdaptiveArrayPool for BitVector storage
- Update FIXED_SLOT_FIELDS to include :bits slot
- Include empty N-D cache fields for empty!() compatibility
BitTypedPool stores 1 bit per element (~8x memory savings vs Vector{Bool}).
Note: unsafe_acquire! not supported - BitArray chunks are immutable.
- Add allocate_vector dispatch for BitTypedPool
- Implement acquire_bits!(pool, n) for 1D SubArray{Bool,1,BitVector}
- Implement acquire_bits!(pool, dims...) for N-D ReshapedArray views
- Add _acquire_bits_impl! for macro transformation support
- Add DisabledPool fallbacks returning native BitArray types
- Add trues!(pool, dims...) for BitArray filled with true - Add falses!(pool, dims...) for BitArray filled with false - Include tuple form and DisabledPool fallbacks - Add _trues_impl!/_falses_impl! for macro transformation
- Add GlobalRef constants for _acquire_bits_impl!, _trues_impl!, _falses_impl! - Update _transform_acquire_calls for acquire_bits!/trues!/falses! - Add :_bits_slot marker in _extract_acquire_types for typed checkpoint - Handle :_bits_slot in _filter_static_types to trigger full checkpoint - Export acquire_bits!, trues!, falses! in main module
- Add test_bitarray.jl with 85 tests covering:
- BitTypedPool structure and state management
- acquire_bits! 1D and N-D operations
- trues!/falses! convenience functions
- DisabledPool fallbacks and macro integration
- Memory efficiency vs Vector{Bool}
- Update test_fixed_slots.jl to use AbstractTypedPool
- Add acquire_bits! to empty! integration test
BREAKING CHANGE: Removed acquire_bits!, trues!, falses! functions.
Use the unified API with Bit sentinel type instead:
- acquire_bits!(pool, n) -> acquire!(pool, Bit, n)
- trues!(pool, dims...) -> ones!(pool, Bit, dims...)
- falses!(pool, dims...) -> zeros!(pool, Bit, dims...)
Changes:
- Add Bit sentinel type for bit-packed boolean storage
- Add get_typed_pool!(pool, ::Type{Bit}) dispatch
- Add zero(Bit)/one(Bit) for fill operations
- Add DisabledPool fallbacks for Bit type
- Remove acquire_bits!, trues!, falses! and their _impl! variants
- Remove macro transformation for removed functions
- Update tests to use new unified API
This provides a consistent API pattern across all element types:
acquire!(pool, Float64, n) # Vector{Float64}
acquire!(pool, Bool, n) # Vector{Bool}
acquire!(pool, Bit, n) # BitVector
- Add _throw_bit_unsafe_error() with helpful message explaining why BitArray cannot use unsafe_wrap (immutable chunks) - Add explicit _unsafe_acquire_impl! dispatches for Bit type that fail-fast before any work is done - Add test verifying error is thrown with helpful message - Fix unused argument warnings in DisabledPool fallbacks
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #14 +/- ##
==========================================
+ Coverage 96.41% 96.45% +0.04%
==========================================
Files 8 8
Lines 1004 1072 +68
==========================================
+ Hits 968 1034 +66
- Misses 36 38 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR introduces comprehensive BitVector pooling support to AdaptiveArrayPools, enabling significant memory savings (approximately 8x) for boolean arrays by using bit-packed storage instead of byte-per-element storage.
Changes:
- Introduced
Bitsentinel type to distinguish bit-packed arrays from standard boolean arrays - Added
BitTypedPoolspecialized pool for managingBitVectorinstances with 1D caching - Integrated
Bittype support into existing APIs (acquire!,zeros!,ones!) with proper error handling for unsupportedunsafe_acquire!
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types.jl | Defines Bit sentinel type, BitTypedPool structure, and adds bits field to AdaptiveArrayPool; includes dispatch for get_typed_pool! |
| src/acquire.jl | Implements allocation dispatch for BitTypedPool, defines zero/one for Bit, adds clear error handling for unsupported unsafe_acquire!, and provides DisabledPool fallbacks |
| src/convenience.jl | Adds zeros!/ones! support for DisabledPool with Bit type using falses/trues |
| src/AdaptiveArrayPools.jl | Exports the Bit type for public use |
| test/test_bitarray.jl | Comprehensive test suite covering all aspects of BitArray pooling including acquisition, state management, error handling, and memory efficiency |
| test/test_fixed_slots.jl | Updates fixed slot infrastructure tests to include BitTypedPool and use AbstractTypedPool type checks |
| test/test_coverage.jl | Adds tests for pooling_enabled dispatch covering both AbstractArrayPool and DisabledPool |
| test/runtests.jl | Includes new BitArray test file in the test suite |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Add back trues! and falses! as convenience wrappers that mirror Julia's built-in trues() and falses() functions for BitArray creation. Changes: - Add trues!(pool, dims...) as wrapper for ones!(pool, Bit, dims...) - Add falses!(pool, dims...) as wrapper for zeros!(pool, Bit, dims...) - Add _trues_impl!/_falses_impl! for macro transformation - Add DisabledPool fallbacks (trues!/falses! -> trues/falses) - Add macro transformation support in _transform_acquire_calls - Add type extraction for trues!/falses! (always Bit type) - Add comprehensive tests including macro integration This provides both API styles: - Original Julia-style: trues!(pool, dims...) / falses!(pool, dims...) - Unified Bit sentinel: ones!(pool, Bit, dims...) / zeros!(pool, Bit, dims...)
Invert the delegation relationship so that trues!/falses! are the canonical BitArray functions (matching Julia's native API), and ones!/zeros! with Bit type delegate to them. Changes: - trues!/falses! now have their own implementations (acquire + fill) - ones!(pool, Bit, ...) delegates to trues!(pool, ...) - zeros!(pool, Bit, ...) delegates to falses!(pool, ...) - Update docstrings to reflect new primary status This follows Julia's semantics where trues/falses are the native BitArray creation functions, not ones/zeros.
…aths Add tests to achieve 100% coverage for convenience.jl BitArray functions: - NTuple form tests for trues!/falses! and zeros!/ones! with Bit type - Generic DisabledPool fallback tests for unknown backends - _trues_impl!/_falses_impl! delegator tests for DisabledPool - _zeros_impl!/_ones_impl! with Bit type NTuple for AbstractArrayPool Coverage: src/convenience.jl 96% → 100%
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.
Summary
This PR introduces comprehensive support for pooling
BitArrays (specificallyBitVectorand its multidimensional views), enabling significant memory savings for boolean arrays compared to standardVector{Bool}.Key Changes
1. New
BitSentinel TypeIntroduced
Bitas a sentinel type to distinguish between bit-packed arrays and standard boolean arrays:acquire!(pool, Bit, n): Returns a pooledBitVector(1 bit per element).acquire!(pool, Bool, n): Returns a pooledVector{Bool}(1 byte per element).2.
BitTypedPoolImplementationBitTypedPooltoAdaptiveArrayPool(accessible via.bits).BitVectors.SubArray{Bool, 1, BitVector}for 1D requests.ReshapedArray{Bool, N, ...}wrapper for N-D requests, maintaining zero-allocation usage where possible.3. API Integrations
falses!(orzeros!) /trues!(orones!) Support:zero(Bit) === falseandone(Bit) === trueto support generic fill operations.4. Memory Efficiency
Vector{Bool}overhead is significant.Usage Example
Testing
test/test_bitarray.jlcovering:zeros!andones!convenience functions.