Skip to content

(refac): Slot-first architecture: remove view cache, isolate legacy#23

Merged
mgyoo86 merged 7 commits intomasterfrom
refac/remove_view_caching
Mar 7, 2026
Merged

(refac): Slot-first architecture: remove view cache, isolate legacy#23
mgyoo86 merged 7 commits intomasterfrom
refac/remove_view_caching

Conversation

@mgyoo86
Copy link
Member

@mgyoo86 mgyoo86 commented Mar 7, 2026

Summary

Replace the views/view_lengths cache in TypedPool with a slot-first architecture
built on _claim_slot!, and isolate legacy (Julia ≤1.10) code under legacy/.

  • Remove view cache: SubArray is stack-allocated via SROA in Julia 1.11+ — caching
    views was slower than creating fresh ones due to memory indirection overhead.
  • Unify slot management: _claim_slot!(tp, n) is now the single primitive for all
    acquisition paths (get_view!, get_array!), eliminating duplicated resize/growth logic.
  • Decouple view/array paths: get_array! uses _claim_slot! directly instead of
    routing through get_view!, removing an unnecessary intermediate SubArray.
  • Consolidate BitTypedPool: empty!, _check_bitchunks_overlap, and display helpers
    moved from state.jl/utils.jl into bitarray.jl (one file per concept).
  • Isolate legacy exports: CACHE_WAYS/set_cache_ways! removed from the 1.11+ path;
    only exported on Julia ≤1.10 where the N-way cache is actually used.

Breaking changes

None for public API. Internal functions renamed:

  • get_nd_array! -> get_array!
  • get_nd_view! -> removed (merged into get_view!)
  • wrap_array -> removed
  • nd_wrappers field -> arr_wrappers

mgyoo86 added 6 commits March 6, 2026 15:30
…ay/view paths

Remove `views` and `view_lengths` fields from `TypedPool` and unify slot
management through `_claim_slot!` as the shared primitive for all acquisition
paths (`get_view!`, `get_nd_array!`, `get_nd_view!`).

Key changes:
- `get_view!` always creates a fresh `SubArray` (stack-allocated via SROA,
  benchmarked faster than cached return due to no memory indirection)
- `get_nd_array!` uses `_claim_slot!` directly instead of routing through
  `get_view!`, with `setfield!` pattern for cache miss (replaces `unsafe_wrap`)
- `get_nd_view!` uses `_claim_slot!` directly instead of `get_view!`
- `_claim_slot!(tp, n)` overload handles memory provisioning; zero-arg
  variant retained for `reshape!` wrapper-only slots

No public API changes. Checkpoint/rewind unaffected (only uses `n_active`).
CUDA extension and legacy path unaffected.
…t! resize coverage

- Remove `wrap_array` from src/acquire.jl (dead code on Julia 1.11+; legacy retains it)
- Remove CUDA `wrap_array` override and import from dispatch.jl (also dead code)
- Remove `wrap_array` testset from CUDA extension tests
- Remove tautological `>= 1` assertion in test_state.jl (already covered by `>= 3`)
- Add "Slot reuse with resize via _claim_slot!" testset: grow, shrink, slot independence
…ields

- get_nd_array! → get_array!
- get_nd_view! → consolidated into get_view! (N-D overload)
- nd_wrappers → arr_wrappers (struct field)
- _store_nd_wrapper! → _store_arr_wrapper!
_claim_slot! is only defined for TypedPool{T}, so the AbstractTypedPool
signature was wider than the actual contract. Other subtypes override
get_view! directly (CuTypedPool) or use a separate path (BitTypedPool
→ get_bitarray!).
Move all BitTypedPool-specific methods from scattered locations into
the version-specific bitarray.jl files (modern + legacy):

- empty!(::BitTypedPool) from state.jl
- _check_bitchunks_overlap from utils.jl
- Display helpers (_default_type_name, _vector_bytes, _count_label,
  _show_type_name) from utils.jl

Struct definitions (Bit, BitTypedPool) remain in types.jl as required
by AdaptiveArrayPool's field declaration. Pure code movement, no logic
changes.
- Remove CACHE_WAYS, set_cache_ways!, and `using Preferences` from
  src/types.jl — these are unused on Julia 1.11+ (setfield!-based
  wrapper cache replaced N-way set-associative cache)
- Move `export CACHE_WAYS, set_cache_ways!` into the legacy branch
  of @static if in AdaptiveArrayPools.jl
- Add forward-reference comment in utils.jl for _check_bitchunks_overlap
  (defined in bitarray.jl, included after utils.jl)
- Remove corresponding tests from test_nway_cache.jl and test_coverage.jl
  (legacy tests remain in test/legacy/test_nway_cache.jl)
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 94.84536% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.71%. Comparing base (b610102) to head (2fbd6af).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/acquire.jl 87.50% 4 Missing ⚠️
src/bitarray.jl 96.66% 1 Missing ⚠️

❌ Your patch status has failed because the patch coverage (94.84%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #23      +/-   ##
==========================================
- Coverage   95.82%   95.71%   -0.11%     
==========================================
  Files          13       13              
  Lines        1820     1820              
==========================================
- Hits         1744     1742       -2     
- Misses         76       78       +2     
Files with missing lines Coverage Δ
src/AdaptiveArrayPools.jl 100.00% <ø> (ø)
src/legacy/acquire.jl 95.23% <100.00%> (ø)
src/legacy/bitarray.jl 100.00% <100.00%> (ø)
src/legacy/state.jl 98.64% <ø> (-0.07%) ⬇️
src/state.jl 98.15% <100.00%> (-0.09%) ⬇️
src/types.jl 95.23% <ø> (-0.60%) ⬇️
src/utils.jl 94.40% <ø> (-0.71%) ⬇️
src/bitarray.jl 93.82% <96.66%> (+1.23%) ⬆️
src/acquire.jl 89.94% <87.50%> (-1.07%) ⬇️
🚀 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 PR refactors the Julia ≥1.11 implementation to a slot-first acquisition architecture (centered on _claim_slot!), removes the old 1D view cache, renames nd_wrappersarr_wrappers, and relocates legacy (≤1.10) behavior under src/legacy/. It also consolidates BitTypedPool-related helpers into the bitarray.jl concept files.

Changes:

  • Replace TypedPool’s cached 1D view machinery with slot-first _claim_slot!, and create fresh SubArray views per call.
  • Rename and standardize the N-D wrapper cache as arr_wrappers and update associated tests/utilities.
  • Move legacy-only APIs (CACHE_WAYS, set_cache_ways!) and legacy N-way cache logic under src/legacy/, adjusting tests accordingly.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/AdaptiveArrayPools.jl Moves CACHE_WAYS/set_cache_ways! export into the legacy branch; adjusts include layout accordingly.
src/types.jl Removes views/view_lengths, renames wrapper cache to arr_wrappers, and updates design notes for ≥1.11.
src/acquire.jl Introduces slot-first _claim_slot!, makes get_view! always produce fresh views, and rewrites get_array! around arr_wrappers.
src/bitarray.jl Updates BitTypedPool wrapper caching to arr_wrappers and relocates BitTypedPool helpers (empty!/debug/display) here.
src/utils.jl Removes BitTypedPool helper methods moved into bitarray.jl; keeps debug validation hooks.
src/state.jl Updates empty!(::TypedPool) to clear arr_wrappers (no more views cache); updates reset! docs accordingly.
src/legacy/acquire.jl Renames legacy get_nd_array!get_array! while keeping N-way cache behavior for ≤1.10.
src/legacy/bitarray.jl Moves legacy BitTypedPool empty!, debug overlap checks, and display helpers into this concept file.
src/legacy/state.jl Removes legacy BitTypedPool empty! (now in legacy/bitarray.jl).
ext/AdaptiveArrayPoolsCUDAExt/dispatch.jl Removes now-deleted wrap_array dependency from CUDA dispatch imports.
ext/AdaptiveArrayPoolsCUDAExt/acquire.jl Switches CUDA unsafe path to get_array! and removes get_nd_* references.
test/runtests.jl Updates version-specific helper to check arr_wrappers on ≥1.11.
test/test_basic.jl Adds coverage for resize/reuse behavior via _claim_slot!.
test/test_state.jl Removes assertions tied to removed 1D view caches.
test/test_nway_cache.jl Removes legacy-only CACHE_WAYS configuration tests; renames nd_wrappers tests to arr_wrappers.
test/test_coverage.jl Moves set_cache_ways! validation coverage to legacy-only test suite.
test/cuda/test_extension.jl Removes wrap_array test now that API is deleted.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

CPU ≥1.11 no longer uses N-way view caching (slot-first _claim_slot!),
so CACHE_WAYS is now defined locally in the CUDA extension via
@load_preference. GPU still benefits from caching (~80 bytes per
view/reshape on CPU heap). Fixes UndefVarError on extension load.
@mgyoo86 mgyoo86 merged commit e9013a7 into master Mar 7, 2026
10 of 11 checks passed
@mgyoo86 mgyoo86 deleted the refac/remove_view_caching branch March 7, 2026 07:18
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