Repository navigation
Conversation
Add `anndata.experimental.read_elem_async`, a coroutine that reads an element of a zarr store. Group readers gather their children, so the columns of a dataframe, the buffers of a sparse matrix, and the elements of an AnnData are read concurrently. Callers gather calls to read many elements or stores at once. The async readers live in a separate registry keyed on zarr.AsyncGroup and zarr.AsyncArray (`_io/specs/async_methods.py`), next to the lazy registry. They use only zarr's async API. The sync path is unchanged; the dataframe, nullable-string, AnnData, and sparse readers share their construction step with the async readers through small helpers. Loop rule: zarr.Group and zarr.Array are read on zarr's event loop, the loop that opened them, also when awaited from another loop. zarr.AsyncGroup and zarr.AsyncArray are read on the running loop. Encodings without an async reader fall back to the sync reader on a dedicated thread pool, so blocked fallbacks cannot starve the executor that zarr's I/O uses. Refs scverse#1897
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2748 +/- ##
==========================================
- Coverage 87.92% 86.34% -1.58%
==========================================
Files 51 52 +1
Lines 8445 8608 +163
==========================================
+ Hits 7425 7433 +8
- Misses 1020 1175 +155
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
mainand wrote the later fix commits. GPT (Codex CLI) and Claude Code review passes reviewed it.Part of #1897, opened as a draft to get your take. I tried the direction from the 2025 comments there: a separate async path on zarr's event loop, with the sync readers behaving as before.
What it adds
anndata.experimental.read_elem_async(elem): a coroutine that returns whatread_elemreturns, zarr only._io/specs/async_methods.py, sharing the construction step with the sync readers.read_elemand fails the whole call (e.g. a node without encoding metadata, adataframe0.1.0, or a third-party encoding registered for the sync reader only).Not in here: callbacks (so no
read_dispatchedproblem),read_elem_lazy, writes, h5py.What we measured
All of
obsfrom 103 AnnData-Zarr stores on S3 (13.3M cells, in region, obstore, zarr 3.4.2).read_elem_async, max 64 requests in flight, one client per bucketobscolumns (2 runs per arm)Known limits
AnnData) is built on the loop thread: zarr's shared I/O loop for sync nodes, the caller's loop for async nodes.zarr.core.sync._get_loop,Group._async_group,Array._async_arraybefore 3.1.4), kept in twoanndata.compathelpers.Questions
asyncinternally forread_elemandwrite_elem#1897?experimentalthe right home for this?