Skip to content

feat: add C-order option for writing sub chunks within shards - #364

Merged
LDeakin merged 27 commits into
zarrs:mainfrom
ilan-gold:ig/c_order_write
Mar 20, 2026
Merged

LDeakin merged 27 commits into
zarrs:mainfrom
ilan-gold:ig/c_order_write

Conversation

@ilan-gold

@ilan-gold ilan-gold commented Mar 14, 2026 •

Copy link
Copy Markdown
Contributor

Background

While investigating zarrs/zarrs-python#152, I discovered that within-shard reads are random in zarrs (which took way longer than I'd like to admit). Even after merging sub chunks and removing the big copy (#358 + #362) the partial reads were still crazy slow. The reason turned out to be the sub chunk layout on disk did not match my mental image.

Solution

I'm adding subchunk_write_order here as an option on CodecOptions with two possible values as of writing - C-ordering and Randomized (default). Then on calls to ShardingCodec.encode, the correct branch is taken (for only bounded arrays as of writing).

Maybe TODOs (now or open issue for later):

  • If the design here makes sense, I'd apply this to encode_unbounded as well especially since it seems like an even lighter refactor there - encoding and writing are already split so we would just slot in between those two steps with this option. I think independent of whether or not the "design" is right (i.e., a global option or CodecOption), encode_unbounded makes sense so I've refactored to implement that.
  • Morton order would probably be simple (famous last words) to implement since it seems like we only need to worry about interleaving one data type, u64. But there is also a crate that does seem to be actively maintained as well (see note in CodecOptions: https://docs.rs/morton-encoding/latest/morton_encoding/)
  • Benchmarking could be nice (in zarr_benchmarks). I have already tried out the combination of zarr-python write order with perf: merge adjacent subchunk reads #358 and can confirm that it gives (the expected) 20x speedup I have come to expect from doing sequential I/o (in my use case).
  • F order for completeness

@codecov

codecov Bot commented Mar 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.82175% with 37 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
zarrs/src/array/codec/array_to_bytes/sharding.rs 80.34% 23 Missing ⚠️
...ay/codec/array_to_bytes/sharding/sharding_codec.rs 96.25% 7 Missing ⚠️
.../codec/array_to_bytes/sharding/sharding_options.rs 74.07% 7 Missing ⚠️
Components Coverage Δ
zarrs 82.94% <88.82%> (+0.05%) ⬆️
zarrs_chunk_grid 88.67% <ø> (ø)
zarrs_chunk_key_encoding 56.36% <ø> (ø)
zarrs_codec 75.44% <ø> (ø)
zarrs_data_type 85.68% <ø> (ø)
zarrs_filesystem 92.69% <ø> (ø)
zarrs_metadata 82.15% <ø> (ø)
zarrs_metadata_ext 84.60% <ø> (ø)
zarrs_object_store 91.25% <ø> (ø)
zarrs_plugin 79.44% <ø> (ø)
zarrs_storage 85.99% <ø> (ø)

📢 Thoughts on this report? Let us know!

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ilan-gold ilan-gold mentioned this pull request Mar 14, 2026
2 of 4 tasks
@ilan-gold
ilan-gold marked this pull request as ready for review March 18, 2026 14:28
@ilan-gold
ilan-gold requested a review from LDeakin as a code owner March 18, 2026 14:28

@LDeakin LDeakin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this is quality! Just a few minor things

I might follow this up with something like https://github.com/zarrs/zarrs/tree/feat/codec_specific_options before releasing because I want to keep codec-specific options decoupled from zarrs_codec.

I can imagine some extra options for sharding. E.g. write to reserved fixed/bounded size regions to enable concurrent partial encoding of subchunks. Shards can be compacted later.

Comment thread zarrs_codec/src/options.rs Resolved
Comment thread zarrs_codec/src/options.rs Resolved
@ilan-gold

ilan-gold commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor Author

I might follow this up with something like https://github.com/zarrs/zarrs/tree/feat/codec_specific_options before releasing because I want to keep codec-specific options decoupled from zarrs_codec.

That totally makes sense - happy to merge that branch into this one and then update where SubchunkWriteOrder gets put if you want

I can imagine some extra options for sharding. E.g. write to reserved fixed/bounded size regions to enable concurrent partial encoding of subchunks. Shards can be compacted later.

No doubt - page aligned for sure too :) This is moving towards composing options which is cool i.e., "bounded size region + page aligned + C" or just "page aligned + morton"

Definitely makes splitting off the options more attractive

@LDeakin

LDeakin commented Mar 19, 2026

Copy link
Copy Markdown
Member

#366 merged

@LDeakin
LDeakin merged commit c49e59a into zarrs:main Mar 20, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants