11from __future__ import annotations
22
3+ import asyncio
34from dataclasses import dataclass
45from itertools import islice , pairwise
56from typing import TYPE_CHECKING , Any , TypeVar
1415 Codec ,
1516 CodecPipeline ,
1617)
17- from zarr .core .common import concurrent_map
1818from zarr .core .config import config
1919from zarr .core .indexing import SelectorTuple , is_scalar
2020from zarr .errors import ZarrUserWarning
@@ -267,9 +267,12 @@ async def read_batch(
267267 else :
268268 out [out_selection ] = fill_value_or_default (chunk_spec )
269269 else :
270- chunk_bytes_batch = await concurrent_map (
271- [(byte_getter , array_spec .prototype ) for byte_getter , array_spec , * _ in batch_info ],
272- lambda byte_getter , prototype : byte_getter .get (prototype ),
270+ # Store handles concurrency limiting internally
271+ chunk_bytes_batch = await asyncio .gather (
272+ * [
273+ byte_getter .get (array_spec .prototype )
274+ for byte_getter , array_spec , * _ in batch_info
275+ ]
273276 )
274277 chunk_array_batch = await self .decode_batch (
275278 [
@@ -367,15 +370,15 @@ async def _read_key(
367370 return await byte_setter .get (prototype = prototype )
368371
369372 chunk_bytes_batch : Iterable [Buffer | None ]
370- chunk_bytes_batch = await concurrent_map (
371- [
372- (
373+ # Store handles concurrency limiting internally
374+ chunk_bytes_batch = await asyncio .gather (
375+ * [
376+ _read_key (
373377 None if is_complete_chunk else byte_setter ,
374378 chunk_spec .prototype ,
375379 )
376380 for byte_setter , chunk_spec , chunk_selection , _ , is_complete_chunk in batch_info
377- ],
378- _read_key ,
381+ ]
379382 )
380383 chunk_array_decoded = await self .decode_batch (
381384 [
@@ -433,14 +436,14 @@ async def _write_key(byte_setter: ByteSetter, chunk_bytes: Buffer | None) -> Non
433436 else :
434437 await byte_setter .set (chunk_bytes )
435438
436- await concurrent_map (
437- [
438- (byte_setter , chunk_bytes )
439+ # Store handles concurrency limiting internally
440+ await asyncio .gather (
441+ * [
442+ _write_key (byte_setter , chunk_bytes )
439443 for chunk_bytes , (byte_setter , * _ ) in zip (
440444 chunk_bytes_batch , batch_info , strict = False
441445 )
442- ],
443- _write_key ,
446+ ]
444447 )
445448
446449 async def decode (
@@ -467,12 +470,12 @@ async def read(
467470 out : NDBuffer ,
468471 drop_axes : tuple [int , ...] = (),
469472 ) -> None :
470- await concurrent_map (
471- [
472- (single_batch_info , out , drop_axes )
473+ # Process mini-batches concurrently - stores handle I/O concurrency internally
474+ await asyncio .gather (
475+ * [
476+ self .read_batch (single_batch_info , out , drop_axes )
473477 for single_batch_info in batched (batch_info , self .batch_size )
474- ],
475- self .read_batch ,
478+ ]
476479 )
477480
478481 async def write (
@@ -481,12 +484,12 @@ async def write(
481484 value : NDBuffer ,
482485 drop_axes : tuple [int , ...] = (),
483486 ) -> None :
484- await concurrent_map (
485- [
486- (single_batch_info , value , drop_axes )
487+ # Process mini-batches concurrently - stores handle I/O concurrency internally
488+ await asyncio .gather (
489+ * [
490+ self .write_batch (single_batch_info , value , drop_axes )
487491 for single_batch_info in batched (batch_info , self .batch_size )
488- ],
489- self .write_batch ,
492+ ]
490493 )
491494
492495
0 commit comments