Encoding a RecordBatch used to hold several full copies of its data at
once: constructors deep-copied every buffer, each column's bytes were
copied twice into a separate body buffer that grew by doubling, the body
was copied again into the IPC message, and _encode_file_batch decoded the
whole message back just to read its length.
Now the column layout (nodes, buffer offsets, body length) is computed
from buffer lengths alone, the message header is built from it, and each
buffer is written once straight into the destination: the pre-sized
output List for encode_arrow_file, or the file itself for
ArrowFileWriter. ArrowArray/RecordBatch take their buffers as owned
values, so callers can move them in with ^.
Encoded bytes are unchanged (cmp against 1.3.0 on every column type, and
on hl7-arrow's real output). encode_record_batch and encode_arrow_file
are ~7x faster in bench_arrow, and hl7-arrow's whole-file peak RSS on a
173 MB batch drops from 5.7 GB to 2.4 GB.
Breaking: passing a buffer variable without ^ or .copy() no longer
compiles.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>