Skip to content

Conversation

@mgyoo86
Copy link
Collaborator

@mgyoo86 mgyoo86 commented Jan 31, 2026

Summary

Unify Bit type API to always return BitVector for SIMD-optimized performance.

⚠️ Breaking Change

acquire!(pool, Bit, n) now returns BitVector instead of SubArray{Bool}.

Why this matters: BitVector operations like count(), sum(), and bitwise ops are 10x~100x faster than SubArray equivalents due to SIMD-optimized chunk algorithms.

Migration: No code changes needed for typical usage. Only affects code that explicitly type-checks for SubArray.

Changes

  • Unified API: Both acquire! and unsafe_acquire! return BitVector for Bit type
  • SIMD Performance: Preserves native BitVector performance (10x~100x faster count())
  • Safety Fix: Replace prod() with safe_prod() for overflow protection
  • Refactor: Extract BitArray logic to dedicated bitarray.jl file

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
Copy link

codecov bot commented Jan 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.88%. Comparing base (03da49d) to head (8e0ff19).
⚠️ Report is 14 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

Copilot AI left a 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! and unsafe_acquire! now return BitVector for SIMD performance
  • Extracted BitArray-specific logic to a new dedicated bitarray.jl file for better code organization
  • Updated documentation for Bit and BitTypedPool types 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.

…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
@mgyoo86 mgyoo86 merged commit cf2a9a3 into master Jan 31, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants