Skip to content

Add fast-path access for metadata properties (dims, shape, dtype) without building full dask task graph #197

Description

@BrianWhitneyAI

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:

  • dtypeself.xarray_dask_data.dtype
  • shapeself.xarray_dask_data.shape
  • dimsDimensions(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

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions