The Zero-copy CSR (Compressed Sparse Row) design is an optimization for reading large-scale graph data (e.g., ~0.75B edges) from columnar storage into Arrow CSR memory.
The Problem: Memory Bloat
In the original implementation, each parallel batch (one per thread) maintained a dense indptr array indexed by the global source row ID. This caused massive memory duplication: if a batch touched only a few rows but the global row ID was high, the indptr was padded with zeros up to the maximum global row ID. For ~50 parallel batches, this resulted in ~40-45 GB of redundant indptr data.
The Solution: Sparse Per-Batch CSR
The design exploits two invariants to replace the dense indptr with a sparse representation:
- Monotonicity: Because morsels are acquired via an atomic counter, each thread receives a non-decreasing sequence of
srcRowIDs. - Disjointness: Each source row is scanned in exactly one morsel, meaning per-batch sets of touched source rows are disjoint.
By using a sparse representation, the per-batch overhead drops from numSourceRows * 8 bytes to distinctSrcRowsInBatch * 16 bytes (storing only the srcRows ID and the counts of edges per row).