Skip to content

gh-150942: Improve performance of csv reader by using _PyList_AppendT… - #155957

Open
imabd645 wants to merge 1 commit into
python:mainfrom
imabd645:fix-csv-append-150942
Open

gh-150942: Improve performance of csv reader by using _PyList_AppendT…#155957
imabd645 wants to merge 1 commit into
python:mainfrom
imabd645:fix-csv-append-150942

Conversation

@imabd645

@imabd645 imabd645 commented Aug 17, 2026

Copy link
Copy Markdown

Description

This PR improves the performance of the csv module's reader by replacing standard PyList_Append calls with the internal _PyList_AppendTakeRef stealing method.

When parsing CSV fields, the C extension previously appended the parsed field to a list and subsequently decremented the reference count of the field. By using the new stealing methods, we avoid the overhead of an unnecessary incref/decref pair and slightly simplify the C implementation.

Changes:

  • Included "pycore_list.h" in Modules/_csv.c.
  • Replaced PyList_Append followed by Py_DECREF with _PyList_AppendTakeRef in the parse_save_field function.
  • Added the corresponding NEWS blurb.

@eendebakpt

Copy link
Copy Markdown
Contributor

Duplicate of #150995?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants