Skip to content

Commit ccf00ea

Browse files
committed
Cache the result of the zero-check
Closes #3627
1 parent b873691 commit ccf00ea

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/zarr/core/codec_pipeline.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,12 @@ async def _read_key(
413413
if chunk_array is None:
414414
chunk_array_batch.append(None) # type: ignore[unreachable]
415415
else:
416+
# The operation array_equal operation below effectively will force the array
417+
# into memory.
418+
# if the result is useful, we want to avoid reading it twice
419+
# from a potentially lazy operation. So we cache it here.
420+
# If the result is not useful, we leave it for the garbage collector.
421+
chunk_array._data = np.asarray(chunk_array._data)
416422
if not chunk_spec.config.write_empty_chunks and chunk_array.all_equal(
417423
fill_value_or_default(chunk_spec)
418424
):

0 commit comments

Comments
 (0)