Repository navigation
Conversation
Loading DiskArrays invalidated ~900 MethodInstances, mostly from methods
that add to Base.Generator(f, ::Any) and zip(x, ::AbstractDiskArray, ...).
- Specialize collect/map on Base.Generator{<:AbstractDiskArray} rather than
overriding the Base.Generator constructor; DiskGenerator is now an alias.
- Remove the untyped catch-all zip error methods.
- Give ChunkIndices the right eltype through its supertype instead of an
eltype method.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Add the dependency-free subpackage lib/DiskArraysCore containing AbstractDiskArray, the interface functions (readblock!, writeblock!, eachchunk, haschunks, chunkexists), the chunk types and the BatchStrategy types. DiskArrays depends on it and re-exports these names, so they are the same objects as before. Packages that only need to subtype AbstractDiskArray can depend on DiskArraysCore without loading the generic array methods (and their invalidations) of DiskArrays. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
To me this sounds like a very good approach, in particular with respect to bringing DiskArrays into HDF5 in a very unintrusive way. I am still not entirely sure if this plan would work out without extensive type piracy between DiskArraysCore.jl and DiskArrays.jl. In the end the problem remains that there will be non-local behavior changes in the code depending on whether or not a user has loaded a package that requires DiskArrays in their environment. So, the whole indexing machinery in a HDF5 dataset would change if somewhere else in the code someone is doing Maybe the better approach for integrating into HDF5 would be to have a DiskArrays extension and add an option to allow e.g. h5open(filename; diskarray=false/true) |
Motivation
Packages that want to be a disk array (e.g.
HDF5.Dataset, JuliaIO/HDF5.jl#1246, Zarr, NetCDF, ...) currently have to depend on all of DiskArrays, which brings in OffsetArrays, LRUCache, ConstructionBase and, more importantly, the methods that DiskArrays adds toBasefunctions forAbstractDiskArray(indexing, broadcast,mapreduce,zip,Generator, ...). Those invalidate compiled code in every session that loads the package, whether or not the user ever touches a disk array through the generic path (916 invalidated MethodInstances onmain, 191 after #345).The interface itself (the abstract type,
readblock!/writeblock!/eachchunk/haschunks/chunkexistsand the chunk types) needs none of that. Splitting it out lets implementers depend only on the interface, and lets the generic implementations be opt-in for the user (using DiskArrays).What this PR does
Adds a dependency-free subpackage
lib/DiskArraysCore(version 0.1.0) containing, moved verbatim fromsrc/:diskarray.jl:AbstractDiskArray,isdisk,readblock!,writeblock!,eachchunk,haschunks,chunkexistschunks.jl:RegularChunks,IrregularChunks,GridChunks,Chunked/Unchunked,ChunkIndex,ChunkIndices,estimate_chunksize, ...BatchStrategytypes (NoBatch,SubRanges,ChunkRead,AllowStepRange, ...), the first ~70 lines ofbatchgetindex.jl, becauseChunked()/Unchunked()default to themDiskArraysdepends onDiskArraysCoreand imports every one of those names, soDiskArrays.AbstractDiskArray === DiskArraysCore.AbstractDiskArrayetc. Nothing changes for current users or for packages that extendDiskArrays.readblock!, etc. (tested). The only code edit besides the move:wrapchunk(the one use of OffsetArrays in the moved files) now lives in DiskArrays.Measured (SnoopCompile
@snoop_invalidations, Julia 1.13):using DiskArraysCoreusing DiskArrays(with #345)Things to decide / known limitations
DiskArraysCore.AbstractDiskArraygets the interface but no genericgetindex,broadcast,mapreduce, ... until DiskArrays is loaded; at that point the existing@implement_diskarray AbstractDiskArraymethods apply to it. So a package depending only on Core needs a fallback for basic indexing (or declares that DiskArrays is needed) and should be designed so both states work. This is the main design question: is this layering acceptable or should Core also carry minimal scalar/blockgetindex?DiskArraysCoreinlib/(monorepo, registered withsubdir = "lib/DiskArraysCore") vs. a separate repository; happy to change.DiskArraysCorehas to be registered before this can be released.[sources]inProject.tomlhandles dev/test on Julia >= 1.11; CI runsPkg.developfirst so 1.10 works too, and runs the Core tests.@refs to them still resolve to the same objects) but I haven't built the docs locally.OffsetArrays(10 invalidations:in(::Any, ::OffsetArray)) is only a dependency of DiskArrays, not Core.Testing
Base.Generator/zip/collect/map).