Work on Version 1.17.0#331
Open
tilo wants to merge 55 commits into
Open
Conversation
PeekableIO: buffer stores raw bytes in external encoding; maybe_transcode applies ext→int conversion on read-out. @buffer_frozen flag prevents premature delegation to @io before rewind, so all bytes consumed during auto-detection are replayable. each_char falls back to ASCII_8BIT (not UTF-8) for sources with no declared encoding. Reader: enforce_utf8_encoding was using force_encoding(utf-8) which silently dropped non-ASCII bytes from ISO-8859-1, Windows-1252, Shift-JIS and other encodings. Now uses line.encoding as the source in encode() for correct transcoding. Use Encoding::ASCII_8BIT consistently (Encoding::BINARY is an alias). Add comprehensive tests: multi-encoding unit tests, transcoding pair integration tests, non-seekable stream transcoding.
…andling, and full test coverage
…uotes (C and Ruby paths) - make buffer_size a public option - auto_row_sep_chars defaults to 4096 - files ending in a lone \r now correctly detected as \r-terminated - minor internal refactor in parse_csv_line_c - added test coverage for quoted-field behavior - added test coverage for line-ending detection - cleaned up Gemfile and some RSpec files - updated documentation and CHANGELOG
…llowing +0/-0 for remove_zero_values; performance update for numeric conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
previous versions of SmarterCSV required that we do a IO.rewind after automatic detection of row_sep and col_sep. This limits the use cases of the gem.
We also want to be able to use it for streaming input.
Work on this branch:
IO.rewindwhen doing auto-detectionThis adds a peekable IO buffer
SmarterCSV 1.17.0
A features-and-quality release — non-seekable streaming inputs, a structured warnings system, Rails-friendly defaults, and a round of parser performance work. No breaking changes; all 1.16.x code works unmodified. Backwards-compatible to Ruby 2.5.
RSpec tests: 1,434 → 2,201 (+767 since 1.16.4).
Headline features
Non-seekable streaming inputs — SmarterCSV now reads directly from any IO, including streams that don't support rewind/seek (pipes, STDIN, Zlib::GzipReader, HTTP/S3 response bodies). No need to materialize the file on disk.
Auto-detection of row_sep/col_sep continues to work on these inputs via an internal rewindable buffer, so the underlying source never needs to rewind.
Structured warnings — auto-detection and config warnings are collected on the Reader as a de-duped histogram (reader.warnings), in addition to being emitted to a log sink.
Class-level SmarterCSV.warnings mirrors SmarterCSV.errors (per-thread, cleared per call).
When Rails.logger is present, warnings route through it at the declared severity; otherwise Kernel#warn. Codes: :chunk_size_default, :header_a_method, :utf8_missing_binary_mode, :no_clear_row_sep, :no_row_sep_found.
New / changed options
buffer_size— now public; peek-buffer chunk size for non-seekable inputs. Default 16_384. Out-of-range values warn and clamp. No effect on seekable inputs (paths, File, StringIO).auto_row_sep_chars— default changed500→4096(sized to cover wide headers in one read). Behavior change: nil/0 no longer means "scan whole file" — they fall back to the default with a warning; the total scan is hard-capped at 64KB.Bug fixes
Performance — 1.16.4 → 1.17.0
Apple M3, Ruby 3.4.7, 40 iterations × 8 runs, median across runs (p10-trimmed). The C parser's core line-parsing (separator splitting, quote/escape handling, multiline stitching) is unchanged from 1.16.0; the C-path changes this cycle are a faster code path for quoted-field-heavy files (the wins) and Unicode-aware blank detection. ~N% error = within ±3%, the run-to-run margin — effectively unchanged.
C-accelerated path (the default)
Quote-heavy / large-field / wide files run 7–22% faster; everything else is within ±3% (effectively unchanged — the short-line / many-tiny-field files show a small consistent uptick from the larger default auto-detection scan window, auto_row_sep_chars; dial it down if that matters).
Ruby fallback path (acceleration: false)
Faster on nearly every file (4–20%), biggest on wide / many-small-field CSVs — from in-place stripping in the no-quote split path, a first-byte fast-reject before numeric conversion, and per-row / per-value overhead removed from the hash transformations. (long_fields_40k and sensor_data sit at parity — not per-field-transform-bound.)
See CHANGELOG.md and docs/releases/1.17.0/ (changes.md, performance_notes.md) for full detail.