Skip to content

Optimize ShouldQuote logic and add write benchmarks#2379

Open
karpinsn wants to merge 1 commit into
JoshClose:masterfrom
karpinsn:shouldQuoteOptimization
Open

Optimize ShouldQuote logic and add write benchmarks#2379
karpinsn wants to merge 1 commit into
JoshClose:masterfrom
karpinsn:shouldQuoteOptimization

Conversation

@karpinsn

Copy link
Copy Markdown

Refactored ShouldQuote in ConfigurationFunctions to reduce per-field overhead:

  • Check leading/trailing spaces first (cheapest check).
  • Fast path: when delimiter is a single char and newline is default, scan the field once instead of making 3-4 separate passes (Contains/IndexOfAny).
  • Slow path: fall through to existing multi-char / custom-newline logic.

Added BenchmarkDotNet benchmarks for ShouldQuote and WriteRecords.

Performance results:
ShouldQuote: 1.154 ms -> 0.854 ms (~26% faster)
WriteRecords: 2.427 ms -> 1.808 ms (~25% faster)

Refactored ShouldQuote in ConfigurationFunctions to reduce per-field
overhead:
- Check leading/trailing spaces first (cheapest check).
- Fast path: when delimiter is a single char and newline is default,
  scan the field once instead of making 3-4 separate passes
  (Contains/IndexOfAny).
- Slow path: fall through to existing multi-char / custom-newline logic.

Added BenchmarkDotNet benchmarks for ShouldQuote and WriteRecords.

Performance results:
  ShouldQuote: 1.154 ms -> 0.854 ms (~26% faster)
  WriteRecords: 2.427 ms -> 1.808 ms (~25% faster)
@karpinsn karpinsn force-pushed the shouldQuoteOptimization branch from 1fb810e to af3e935 Compare May 21, 2026 20:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant