Repository navigation
Compute zarr shards one chunk at a time to reduce peak memory - #4907
Merged
alejoe91 merged 3 commits intoNov 10, 2026
Merged
Conversation
Member
|
Thanks @h-mayorquin I like this, while we discuss on bigger infrastructural changes! I exposed the |
alejoe91
approved these changes
Nov 9, 2026
Member
|
@h-mayorquin this is what I get compared to main and #4833
So this is great! Wanna look at my changes before merging? |
Contributor
Author
|
I am Ok with your changes go ahead. |
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.

@alejoe91 asked in #4833 for an alternative that keeps the shard handling inside the zarr writer. Right now each job computes and writes a whole shard at once. This PR keeps one worker per shard but the worker computes the chain one zarr chunk at a time and writes as many whole chunks at once as fit in a budget per worker,
write_buffer_megabytes(500 MB). Writing in groups matters because every partial write makes zarr-python read the whole shard and write it again. With 60 s shards of 1 s chunks, writing chunk by chunk rewrites each shard 60 times, and with 384 float32 channels the budget brings this down to 6. Without shards a job is one zarr chunk and nothing changes.write_buffer_megabytesis a fixed value inside the zarr writer instead of a new job kwarg. I made it per worker following the precedent ofchunk_memoryin the job kwargs. Depending on how the discussion in #4905 goes, we can make it public to give the user control over it. I picked 500 MB because in my tests 10 chunks per write was close to the speed of writing the shard once while keeping the memory of writing chunk by chunk. Against #4833 this uses about 0.4 GB more, the size of the buffer, and is 2.5 to 10 times faster:bandpass_filterto float32 and mediancommon_referencephase_shiftin front of the same chainSame data as in my review of #4833, the first 60 s of a four-shank Neuropixels 2.0 recording (384 channels, 30 kHz), with 1 s chunks and 60 s shards, one worker, one run each (two for raw), and the peak increase of the resident memory on my Linux laptop.