Skip to content

PERF: build read_csv pyarrow string columns without the GIL, deferring the wrap#66277

Draft
jbrockmendel wants to merge 1 commit into
pandas-dev:mainfrom
jbrockmendel:perf-read_csv-deferred-strings
Draft

PERF: build read_csv pyarrow string columns without the GIL, deferring the wrap#66277
jbrockmendel wants to merge 1 commit into
pandas-dev:mainfrom
jbrockmendel:perf-read_csv-deferred-strings

Conversation

@jbrockmendel

Copy link
Copy Markdown
Member

Follow-up to GH-65283. _string_pyarrow_utf8 now mallocs offsets/validity/data inside a single nogil region and returns a raw pending-column handle; materialization into a pyarrow Array (via capsule-backed foreign buffers) happens once per column at the end of the read, and low_memory chunks combine zero-copy into one chunked ExtensionArray. Also caches the pyarrow helper imports and the per-reader string-target decision, which previously re-ran option lookups per column chunk while holding the GIL.

Draft, sequenced after GH-66275: standalone this is neutral on today's serial and parallel paths (the GIL sections it removes are not the bottleneck there); on that PR's reworked parallel path it is a large win — str 86.2 → 64.4 ms (−25%). Will convert to ready once GH-66275 lands and re-verify on the rebase (a 3-line follow-up there lets workers hand raw pending columns to the gather for main-thread materialization).

🤖 Generated with Claude Code

@jbrockmendel jbrockmendel force-pushed the perf-read_csv-deferred-strings branch from f6f4268 to a094c1b Compare July 10, 2026 14:51
@jbrockmendel jbrockmendel added Performance Memory or execution speed performance IO CSV read_csv, to_csv labels Jul 10, 2026
@jbrockmendel jbrockmendel force-pushed the perf-read_csv-deferred-strings branch from a094c1b to 876858d Compare July 10, 2026 18:03
…g the wrap

_string_pyarrow_utf8 now mallocs offsets/validity/data inside a single
nogil region and returns a raw handle; materialization into a pyarrow
Array (via capsule-backed foreign buffers) happens once per column at
the end of the read, and low_memory chunks combine zero-copy into one
chunked ExtensionArray. Also caches the pyarrow helper imports and the
per-reader string-target decision, which previously re-ran option
lookups per column chunk while holding the GIL.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jbrockmendel jbrockmendel force-pushed the perf-read_csv-deferred-strings branch from 876858d to 40fd58c Compare July 11, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

IO CSV read_csv, to_csv Performance Memory or execution speed performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant