liveBook · Manning

Chunk granularity

As explained in Fast Python: High performance techniques for large datasets

Chunk granularity is the amount of data or content assigned to each unit when a larger source is divided into chunks for processing, storage, transfer, or retrieval.

Chunk granularity sets how many array elements each Zarr chunk holds. Chunks partition large arrays into manageable units, and their shape can be specified when an array is created. section 8.4.2

Choose chunk size for the workload and storage system:

  • Calibrate against the algorithms and access patterns; avoid chunks that are too small, and keep chunks comfortably in memory. section 8.4.3
  • Try different values across dimensions: chunk shape affects performance and whether work fits in memory. section 8.4.3
  • Account for the store: DirectoryStore can struggle with thousands of files in one directory; NestedDirectoryStore distributes chunks into subdirectories. section 8.4.3

A two-dimensional array

An array with shape (3,976,554, 210) uses chunks of (20,000, 210), grouping 20,000 rows while keeping all 210 columns together. This choice assumes all individuals will be read at once. section 8.4.3

Chunk shape        : (41632,)
Chunks initialized : 8/8

A one-dimensional Zarr array reports a chunk shape of (41,632,) and eight initialized chunks. section 8.4.2

How Fast Python: High performance techniques for large datasets covers it

How deep it goes
Explains chunk-shape choices and storage trade-offs, but leaves workload-specific calibration to the user.
Examples
Compares 41,632-element chunks with 20,000-by-210 chunks for arrays of different shapes.
What it assumes
Choose sizes based on array dimensions and intended algorithms; the treatment does not teach storage concepts from zero.
What you can do after
Configure chunk dimensions and calibrate their size against access patterns, memory, and storage limits.
How it connects
Relates chunk sizing to Zarr arrays, DirectoryStore, and NestedDirectoryStore.

Also explained in

Compare how 3 books explain chunk granularity →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast Python: High performance techniques for large datasets. The section links point to the parts of the book it draws on.