`csv.reader` calls the state machine for every character needlessly
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
The state machine:
https://github.com/python/cpython/blob/bbcb75c986c47887e6c0757e63d59cd7af544f39/Modules/_csv.c#L726
is called for every character processed by csv.reader:
Even putting aside sophisticated SIMD or branching optimizations, it could be more efficient.
Most time is likely to be spent in a field (IN_FIELD, IN_QUOTED_FIELD). It's more efficient to find interesting characters (ie: escapes, quotes) and just copy the whole slice in between.
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
- gh-138214
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in Modules/_csv.c at the state machine around line 726 and the csv.reader processing around lines 969-974. Review linked PR gh-138214 before starting, then verify that any change preserves csv.reader behavior while avoiding needless per-character state-machine calls.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100