perf(polars): rewrite DataFrame serializer with typed column iterators - #30
Merged
Conversation
Pull the ryu/itoa/bool/string field writers out of FieldValue::write_lp into pub(crate) functions so the DataFrame serializer can reuse them and the two paths cannot diverge on formatting rules. No behavior change. Refs #29 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replace per-cell AnyValue access and format! allocations with typed ChunkedArray iterators advanced in lockstep, writing through the shared ryu/itoa value writers into a single output buffer: - Columns are resolved, downcast, and name-escaped once before the row loop; exotic dtypes keep the AnyValue fallback with unchanged stringification semantics. - All-null-field rows are dropped by truncating the buffer; per-line Strings and the final join are gone. - Timestamps use itoa with unit conversion baked into the reader. Floats now format via ryu on both paths (matching Point), so extreme magnitudes emit exponent notation instead of expanded decimals. Criterion benchmark (10k rows x 25 columns, wide numeric telemetry): 25.9ms -> 10.2ms, ~2.5x faster (387K -> 976K rows/s). Closes #29 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #30 +/- ##
==========================================
- Coverage 83.44% 82.63% -0.81%
==========================================
Files 10 10
Lines 1836 1981 +145
==========================================
+ Hits 1532 1637 +105
- Misses 304 344 +40 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
alespour
approved these changes
Jul 15, 2026
alespour
left a comment
Contributor
There was a problem hiding this comment.
nice improvements, looks all good to me 🚀
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.
Closes #29.
The polars DataFrame → line protocol serializer accessed data row-by-row via
col.get(row_idx)(per-cellAnyValuedispatch) and allocated an intermediateStringper field viaformat!, giving it the opposite performance character of thePointpath. This PR rewrites it on top of thePointpath's machinery, in two commits:FieldValue::write_lpinto sharedpub(crate)functions. Pure refactor.dataframe_to_line_protocol:ChunkedArrayiterators, and name-escaped once before the row loop; iterators advance in lockstep per row (chunk boundaries handled natively — covered by a new test).Strings or finaljoin.AnyValuefallback with unchanged stringification semantics.Benchmark
New criterion bench (
cargo bench --features polars), 10k rows × 25 columns (1 string tag, 20×f64, 4×i64, datetime timestamp) — the wide-numeric parquet-backfill shape from the user report:~2.5× faster (criterion: −60% ± 2%, p < 0.05). Remaining time is dominated by ryu float formatting, which is inherent to the output.
Semantics
Public API unchanged; all pre-existing tests pass unmodified except
to_timestamp's unit test, which was rewritten to pin the same dtype/precision matrix against the newtimestamp_reader(the old function became dead code). Two tests added: narrow/unsigned dtype suffixes, and multi-chunk columns.One deliberate, visible change: floats now format via ryu on the DataFrame path too (matching
Point), so extreme magnitudes emit exponent notation (1e30) instead of expanded decimals. Line protocol accepts both.🤖 Generated with Claude Code