Commit 69a37e8
Fix getindex invalidation from AbstractArray + BlockIndices (#499)
## Summary
- `getindex(::AbstractArray{T,N}, ::BlockIndices{N})` caused **12,082
method invalidations** when loading BlockArrays
- Removed the `AbstractArray` fallback and added specialized `unblock`
methods in `views.jl` that handle `BlockIndices` on non-blocked axes
(e.g. `Base.OneTo`) by decomposing into block-level + sub-indexing
- The `LayoutArray` specializations (covering all `AbstractBlockArray`
types) and `AbstractBlockedUnitRange` methods are unchanged
## Context
When profiling the TTFX of ModelingToolkit's DAE pipeline, `BlockArrays`
was identified as the #2 source of method invalidations. The
`getindex(::AbstractArray{T,N}, ::BlockIndices{N})` method invalidated
compiled instances of `getindex` for all `AbstractArray` types because
`BlockIndices <: AbstractArray`, triggering recompilation of
fancy-indexing paths.
## Changes
- `src/blockaxis.jl`: Removed `getindex(b::AbstractArray{T,N},
K::BlockIndices{N})` fallback (line 10)
- `src/views.jl`: Added two `unblock` specializations:
- For `AbstractUnitRange{<:Integer}` axes: decomposes `BlockIndices`
into `block()` + regular sub-indices
- For `AbstractBlockedUnitRange` axes: preserves original
direct-indexing behavior
## Design rationale
The `AbstractArray` fallback was needed because `unblock` in
`to_indices` recursively calls `getindex(axis, BlockIndices)`. For
non-blocked axes like `Base.OneTo`, there was no handler, causing
infinite recursion without the fallback. The fix intercepts at the
`unblock` level instead, using `getindex(::AbstractUnitRange,
::Block{1})` (which returns the whole range for non-blocked types)
followed by standard sub-indexing.
## Test plan
- [x] Full test suite passes locally (2,318 pass, 2 broken
(pre-existing), 0 fail)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: ChrisRackauckas-Claude <accounts@chrisrackauckas.com>1 parent cd73466 commit 69a37e8
2 files changed
+24
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | 10 | | |
12 | 11 | | |
13 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
14 | 20 | | |
15 | 21 | | |
16 | 22 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
21 | 38 | | |
22 | 39 | | |
23 | 40 | | |
| |||
0 commit comments