Skip to content

perf: reduce CSV field copy amplification on 4.2-dev - #32769

Merged
XuPeng-SH merged 1 commit into
4.2-devfrom
codex/32751-csv-direct-42
Nov 15, 2026
Merged

XuPeng-SH merged 1 commit into
4.2-devfrom
codex/32751-csv-direct-42

Conversation

@XuPeng-SH

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Related to #32751. Port of main #32766.

What this PR does / why we need it:

CSV fragments spanning read blocks were assembled into a temporary growing buffer and then copied into the row buffer, repeating allocation even with a reusable row buffer. Append fragments directly into the caller-owned row/lookahead accumulator, retaining the single-block path.

Adapt the change to 4.2's raw record bounds and memory reservation callbacks. Growth grants still precede appends, and rejected lookahead preserves the prior empty-fragment error result. Keep the existing conservative reservation envelope.

Six alternating Linux/amd64 CPU benchmark samples with Go 1.26.4:

  • Reused plain 1 MiB / 8 MiB fields: 3,399,680 / 43,220,992 B/op -> 0; time improves about 44% / 55%. Four concurrent 1 MiB readers improve about 58%.
  • Tradeoff: serial small/wide CSV framing is about 3.6% / 3.5% slower (roughly 1 ns/field). Cold row capacity after an 8 MiB field is about 9.07 MiB versus 8 MiB (1 MiB: 1.20 versus 1 MiB). This targets large-value ingestion and does not make every workload better.
  • Parallel fixtures keep mutable row headers local to each goroutine. Corrected small-field concurrent controls do not establish a consistent regression; initial shared-header samples are superseded.

Validation: full csvparser normal/race/vet, focused external admission/reset/typed-boundary normal/race controls, 4,176 baseline/head input/config/block comparisons, and final incremental lint (0 issues). CN RSS evidence is from sibling main #32766; this port has branch-specific component and consumer validation. The pre-existing sealed-CR panic found in baseline controls is addressed independently by #32768.

Full hosted CI is pending. Maintained benchmarks cover cold/reused, small/wide/quoted/large inputs and independent concurrent readers.

Preserve 4.2 raw admission and growth-denial semantics while reusing caller-owned buffers.

Related to #32751.
@XuPeng-SH
XuPeng-SH requested a review from aunjgr as a code owner November 15, 2026 13:21
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify

mergify Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

This pull request is merged.

@XuPeng-SH

XuPeng-SH commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor Author

mo-bot review · mo-bot-local · done

Commit: 9f69d70ed44ec82ec0e80c0d2022d8237d81bf87

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 9f69d70ed44ec82ec0e80c0d2022d8237d81bf87

Assessment: approve

Direct fragment appends reuse the existing accumulator and preserve 4.2 raw bounds, grant/error behavior and ownership. The disclosed small/wide CPU cost and larger retained capacity are reasonable tradeoffs for substantial large-field allocation and CPU savings. No new state or reservation mechanism is added.

Model: gpt-6.1-sol / max

Session: 01a1a004-90c3-73b1-acc9-3d4636452003 · slot 0 · generation 0

Validation:

  • Reviewed the complete two-file delta, all three scanner callers, admission/lease/pending-row consumers, benchmark fixtures, three discussion entries and current linked issue context.

  • Isolation preflight and three complete-parser probe roots passed: exact values/reset/lines, 20 bound/grant/denial/read-error controls, and an unchanged baseline sealed-CR panic control.

  • Frozen-source, gofmt/whitespace, unchanged reservation-owner, probe-provenance and command/source/exit/log audit passed.

  • Assessed reported owning/consumer normal/race/vet, 4,176 differential comparisons and six alternating branch-specific benchmark samples.

Limitations:

  • The probe replaces four external dependencies with documented scaffolding; native leases, full-package/race execution and real SQL/file-service behavior were not locally exercised. Author raw runtime/performance logs were unavailable.

  • Reported serial small/wide framing is approximately 3.6%/3.5% slower; retained row capacity increases. Corrected small parallel controls are inconclusive, and sibling-main RSS evidence does not establish 4.2 whole-CN or idle-memory gains.

  • Six hosted checks remain pending/queued. The pre-existing sealed-CR panic remains in this independent head and is addressed separately by #32768.

This branch was previously deployed

1 inactive deployment
ci — 9f69d70e Deployed Nov 15, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement kind/test-ci size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants