Summary
Properties derived from xarray_dask_data — namely dims, shape, and dtype — currently force construction of the full delayed dask task graph just to read lightweight metadata. Building that task graph can be computationally expensive, yet several readers can access these values cheaply from their underlying file metadata. We should add a fast path so requesting metadata-only properties doesn't pay the cost of assembling the delayed array.
Current behavior
In both BioImage (bioio/bio_image.py) and the base Reader (bioio_base/reader.py), these properties route through xarray_dask_data:
dtype → self.xarray_dask_data.dtype
shape → self.xarray_dask_data.shape
dims → Dimensions(dims=self.xarray_dask_data.dims, shape=self.shape)
The first access to xarray_dask_data triggers full task-graph construction (and mosaic stitching logic), which is overkill when the caller only wants shape/dtype/dims.
Proposed change
Introduce an optional fast path for metadata access:
- Allow readers to override lightweight
dims/shape/dtype (and ordering) directly from their native metadata, falling back to the existing xarray_dask_data-derived implementation when not provided.
BioImage should prefer the reader's fast path when available.
Relevant readers with a known fast path
bioio-czi (CZI)
bioio-ome-zarr (OME-Zarr)
bioio-nd2 (ND2)
These formats expose dimension sizes / dtype in metadata without needing the full delayed array.
Notes / considerations
- Keep the default behavior unchanged for readers that don't implement the fast path.
- Ensure correctness for mosaic-stitched images, where
BioImage.shape/dims reflect the stitched result rather than raw reader dims.
- Coordinate the base-class interface change in
bioio-base with the plugin readers above.
Tracking checklist
Summary
Properties derived from
xarray_dask_data— namelydims,shape, anddtype— currently force construction of the full delayed dask task graph just to read lightweight metadata. Building that task graph can be computationally expensive, yet several readers can access these values cheaply from their underlying file metadata. We should add a fast path so requesting metadata-only properties doesn't pay the cost of assembling the delayed array.Current behavior
In both
BioImage(bioio/bio_image.py) and the baseReader(bioio_base/reader.py), these properties route throughxarray_dask_data:dtype→self.xarray_dask_data.dtypeshape→self.xarray_dask_data.shapedims→Dimensions(dims=self.xarray_dask_data.dims, shape=self.shape)The first access to
xarray_dask_datatriggers full task-graph construction (and mosaic stitching logic), which is overkill when the caller only wantsshape/dtype/dims.Proposed change
Introduce an optional fast path for metadata access:
dims/shape/dtype(and ordering) directly from their native metadata, falling back to the existingxarray_dask_data-derived implementation when not provided.BioImageshould prefer the reader's fast path when available.Relevant readers with a known fast path
bioio-czi(CZI)bioio-ome-zarr(OME-Zarr)bioio-nd2(ND2)These formats expose dimension sizes / dtype in metadata without needing the full delayed array.
Notes / considerations
BioImage.shape/dimsreflect the stitched result rather than raw reader dims.bioio-basewith the plugin readers above.Tracking checklist
bioio-base: add optional fast-path interface — Add fast-path interface for metadata properties (dims, shape, dtype) bioio-base#72bioio: prefer reader fast path inBioImage(this repo)bioio-czi: implement fast path — Implement fast-path metadata properties (dims, shape, dtype) from CZI metadata bioio-czi#104bioio-ome-zarr: implement fast path — Implement fast-path metadata properties (dims, shape, dtype) from OME-Zarr metadata bioio-ome-zarr#149bioio-nd2: implement fast path — Feature Request: Implement fast-path metadata properties (dims, shape, dtype) from ND2 metadata bioio-nd2#47