-
Notifications
You must be signed in to change notification settings - Fork 0
PR: N-way Cache for unsafe_acquire!
#5
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 CACHE_WAYS=4 constant for N-way set associative cache - Remove nd_views field (ReshapedArray needs no caching) - Add nd_next_way field for round-robin replacement counter - Implement linear search + round-robin replacement in get_nd_array! - Update empty! to handle new cache structure N-way cache prevents thrashing when alternating between different array dimensions in the same slot. Each slot can cache up to 4 different dimension patterns, returning cached Array instances instead of calling unsafe_wrap (which allocates 112 bytes).
- Add test_nway_cache.jl with thrashing prevention tests - Verify type checks (ReshapedArray vs Array returns) - Test cache invalidation on vector resize - Confirm CACHE_WAYS constant is accessible - Include new test file in runtests.jl
- Replace constant CACHE_WAYS with Preferences-based configuration - Add set_cache_ways!(n) function for runtime configuration - Support range 1-16 with validation and helpful error messages - Export CACHE_WAYS and set_cache_ways! from module - Add comprehensive tests for validation logic Users can now configure N-way cache size via: 1. AdaptiveArrayPools.set_cache_ways!(n) (requires restart) 2. LocalPreferences.toml: [AdaptiveArrayPools] cache_ways = n
- Add 4-way alternating zero-allocation test - Add 5-way acquire! test (ReshapedArray always 0 alloc) - Add 5-way unsafe_acquire! test (cache eviction causes alloc) - Add multiple slots with N-way cache test - Reorganize into 'N-way Cache' and 'N-way Zero-Allocation' testsets
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5 +/- ##
==========================================
+ Coverage 97.16% 97.27% +0.10%
==========================================
Files 6 6
Lines 424 440 +16
==========================================
+ Hits 412 428 +16
Misses 12 12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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 PR implements an N-way set associative cache for unsafe_acquire! to eliminate allocation thrashing when alternating between different array dimension patterns. The implementation adds a configurable cache (default 4 ways) that allows each pool slot to cache multiple dimension patterns using round-robin eviction.
Key Changes
- N-way set associative cache with configurable ways (default: 4) prevents cache thrashing when alternating between dimension patterns
- Preferences.jl integration for runtime configuration with validation (valid range: 1-16)
- Comprehensive test suite demonstrating zero-allocation behavior for patterns within cache capacity
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/types.jl | Adds CACHE_WAYS configuration with Preferences.jl, updates TypedPool structure with N-way cache fields (nd_arrays, nd_dims, nd_ptrs, nd_next_way), removes obsolete nd_views field |
| src/core.jl | Implements N-way cache logic in get_nd_array! with linear search for cache hits and round-robin replacement for misses, updates empty! to clear new cache fields |
| src/AdaptiveArrayPools.jl | Exports CACHE_WAYS constant and set_cache_ways! function for public API |
| test/test_nway_cache.jl | Adds comprehensive tests for N-way cache functionality, configuration validation, allocation behavior, cache invalidation, and multi-slot scenarios |
| test/runtests.jl | Includes new test file in test suite |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
Implement N-way set associative cache for
unsafe_acquire!to prevent thrashing when alternating between different dimension patterns.Changes
Core Implementation
CACHE_WAYSdimension patterns (default: 4)Performance
API Comparison
acquire!ReshapedArrayunsafe_acquire!ArrayConfiguration (Preferences.jl)
Option 1: Programmatic
Option 2: LocalPreferences.toml