Skip to content

gh-156748 : Performance - Use takeref append in _csv - #156749

Open
brittanyrey wants to merge 2 commits into
python:mainfrom
brittanyrey:b-perf-csv-append-takeref
Open

gh-156748 : Performance - Use takeref append in _csv#156749
brittanyrey wants to merge 2 commits into
python:mainfrom
brittanyrey:b-perf-csv-append-takeref

Conversation

@brittanyrey

@brittanyrey brittanyrey commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Reduce refcount churn by consuming the reference instead in lieu of calling append and decreffing.

Benchmark base patched delta
50 fields × 200 rows 537.7 µs 508.3 µs −5.5%
quoted + embedded separators/newlines 468.9 µs 435.8 µs −7.1%
all-empty fields (50 × 200) 173.6 µs 150.0 µs −13.6%
2 fields × 200 rows 24.0 µs 23.3 µs −2.9% (noise 3.3%)
5 × 500-char fields (control) 2517.7 µs 2508.2 µs −0.4% (noise 21%)
# 50 fields x 200 rows
data = "\n".join(",".join(f"f{j}" for j in range(50)) for _ in range(200))
list(csv.reader(io.StringIO(data)))

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.

1 participant