Sub topic 15
Limits and trade-offs: when Arrow does not help
This chapter assumes you have read the earlier chapters on buffers and validity bitmaps, schemas, tables, zero-copy sharing, pandas interoperability, IPC, Parquet and datasets. It covers where Arrow gives you little or nothing, where it costs you something, and how to pick the right tool for a data-exchange problem.
What Arrow actually saves
Arrow removes one specific cost: converting values between formats when data moves between tools. If two libraries both understand the Arrow layout, they can share the same buffers. They don't need to parse text, rebuild objects or copy columns.
That is a narrow benefit. It matters when conversion is a large part of your runtime. It does not matter when your time goes to network latency, disk reads, a slow algorithm or a query that touches one row.
Zero-copy has conditions
Zero-copy is not a property of Arrow in general. It holds only when the source layout matches the target layout exactly. The earlier NumPy example worked because a primitive int64 array with no nulls is already a plain contiguous run of 8-byte values.
Here is what happens when a null appears:
import pyarrow as pa
arr = pa.array([1, None, 3], type=pa.int64())
try:
arr.to_numpy(zero_copy_only=True)
except pa.ArrowInvalid as e:
print("zero-copy refused:", e)
copied = arr.to_numpy(zero_copy_only=False)
print(copied)
print(copied.dtype)NumPy integer arrays have no validity bitmap. To represent the missing value, pyarrow has to build a new float64 array with nan in it. The data is copied and the type changes. The zero_copy_only=True flag turns this silent cost into an error you can see.
The same pattern appears in several places:
| Source | Target | Zero-copy? | Why |
|---|---|---|---|
| Primitive array, no nulls | NumPy | Yes | Same contiguous values |
| Primitive array with nulls | NumPy | No | NumPy needs a sentinel such as `nan` |
| String or binary array | NumPy | No | NumPy gets Python objects, not offsets and bytes |
| Chunked column with several chunks | NumPy | No | Chunks must be joined into one buffer |
| Table with numeric columns | pandas | Often not | pandas by default consolidates columns into 2D blocks |
| Boolean array | NumPy | No | Arrow packs booleans as bits, NumPy uses one byte each |
Check each conversion that sits on a hot path. Do not assume it is free.
Immutability and the cost of changing data
Arrow buffers are meant to be shared by many readers, so arrays are immutable. You cannot assign into an array:
import pyarrow as pa
arr = pa.array([1, 2, 3])
try:
arr[0] = 10
except TypeError as e:
print("cannot modify:", e)
updated = pa.array([10, 2, 3])
print(updated.to_pylist())"Updating" means building a new array. For a workload of many small in-place edits, such as counters, a row cache or an application's working state, this is the wrong model. Arrow fits read-heavy, batch-oriented work where you create a column once and read it many times.
Immutability also has a memory side effect. A slice is a view onto the parent's buffers. If you keep a one-element slice of a million-row array, the whole million-row buffer stays alive. Be aware of this when you store small pieces of large tables in a long-lived cache.
Row-at-a-time access works against the layout
A columnar layout is fast when you scan many values of one column. It is slow when you fetch every field of one record. Reading a single row means touching one buffer per column, and each scalar access creates a Python object.
import pyarrow as pa
import pyarrow.compute as pc
table = pa.table({"id": list(range(1000)), "score": [float(i) for i in range(1000)]})
# Slow pattern: one Python object per value
total = 0.0
for i in range(table.num_rows):
total += table["score"][i].as_py()
# Fast pattern: one call over the whole column
total_fast = pc.sum(table["score"]).as_py()
print(total == total_fast)Both give the same answer. The loop pays Python overhead 1000 times, and for large tables it can be orders of magnitude slower than the single compute call. If you cannot express your logic as column-wise operations, Arrow gives you little speedup over plain Python lists.
For the same reason, Arrow is a poor fit for transactional workloads that look up, insert and update single records. A row-oriented database or a key-value store suits those better.
Small data and fixed overhead
An Arrow array carries metadata: a schema, buffer pointers, and padding so buffers align to 64 bytes. For a few hundred values, this overhead is larger than the data. Starting up a schema, a record batch and a writer for a 10-row payload costs more than sending JSON.
Arrow pays off as data grows, and in particular when you send many rows per batch. Very small batches, such as one row per message, lose most of the benefit because every batch repeats framing and the per-call overhead dominates.
Size on disk and the Parquet question
The IPC file format stores buffers close to their in-memory form. That makes reads fast and memory-mappable, but files are usually larger than Parquet. Parquet applies encodings such as dictionary and run-length encoding, and then compression.
IPC supports optional compression (LZ4 and ZSTD) per buffer. Compressed buffers must be decompressed on read, so you lose memory mapping with no copy.
The rule of thumb from the Parquet chapter still applies:
- Use Parquet for long-term storage, large datasets and data shared across teams. Storage and bandwidth are the bottleneck, and column statistics let scans skip data.
- Use IPC for short-lived exchange, caches and hand-offs between processes on the same machine. Decode speed and zero-copy reads are what matter.
Dependencies and compatibility
Arrow is a specification with several implementations. Two practical risks follow.
- Version and feature gaps. A newer type, such as a view type or a run-end encoded array, may not be supported by every library you hand data to. Test the whole path with real data.
- Type mismatches at the edges. Arrow has types that NumPy and pandas lack, such as
decimal128, nested lists,date32and nanosecond-to-day timestamp ranges. Converting them may produce object columns, lose precision or raise an out-of-bounds error.
The pyarrow package is also a large install (tens of megabytes). On a constrained runtime, such as a small serverless function, this may be a reason to avoid it for a trivial task.
Choosing the right tool
Arrow is a layer under other choices, not a replacement for them. Pick based on where the data moves.
Use this table when a design is not obvious:
| Situation | Better choice | Reason |
|---|---|---|
| Archive data for months | Parquet | Smaller files, column statistics |
| Share a table between two processes on one host | IPC file with memory map | No decode step, no copy |
| Pass an array from one native library to another in one process | C data interface | Pointer hand-off, no serialization |
| Stream results from a service | Flight | Streams record batches over gRPC |
| Fetch query results from a database into Python | ADBC | Returns Arrow batches directly |
| Update individual records often | Row-oriented database | Arrow arrays are immutable |
| Payload of a few rows | JSON or similar | Arrow's fixed overhead dominates |
Checking whether Arrow will help
Before you commit to Arrow, measure. A short checklist:
- Profile the pipeline. If conversion or serialization is not a large share of time, Arrow will not change much.
- Check that your data types map cleanly. Count the columns with nulls, strings or nested types, because these break zero-copy.
- Check batch size. Aim for batches of thousands to many thousands of rows, not single rows.
- Check whether every tool in the path speaks Arrow. One non-Arrow step in the middle forces a conversion that can cancel the gains on either side.
Exercise
A service receives one JSON-like record at a time, updates a few fields, and writes it back, thousands of times per second. A teammate proposes keeping the records in Arrow tables for speed. Give two reasons Arrow is a poor fit, and name a better alternative.
Show answer
Arrow arrays are immutable, so each update means building a new array or table. A columnar layout also makes single-record access slow, because each row read touches one buffer per column and creates Python objects. Per-record batches also waste the fixed overhead of schemas and padding. A row-oriented database or a key-value store suits this workload better.
Exercise
You call pa.array([1, None, 3], type=pa.int64()).to_numpy(zero_copy_only=True). What happens, why, and what does to_numpy(zero_copy_only=False) return?
Show answer
It raises pyarrow.ArrowInvalid, because a null needs a validity bitmap and NumPy integer arrays have none, so a zero-copy view is impossible. With zero_copy_only=False, pyarrow copies the data into a float64 array and writes nan for the null, giving [ 1. nan 3.].
Exercise
You need to store a 200 GB dataset for a year and query a few columns now and then. Do you choose Arrow IPC files or Parquet, and why?
Show answer
Parquet. Its encodings and compression make files smaller, and its column statistics and column layout let dataset scans skip data and read only the needed columns. IPC files are larger and are designed for fast, short-lived exchange rather than long-term storage.