perf: optimize struct_to_json (10% faster)#4927
Conversation
struct_to_json (10% faster)
|
The PR description reports
|
|
The description says the PR replaces "the per-value byte scan" with "a single vectorizable column-wide escape scan." The diff does no such thing. String escaping is still per value inside the row loop via
|
|
|
|
The Rust tests cover Bool/Int32/Utf8, nested struct, and null handling with
|
|
|
… tests Adds Utf8View to the Quoted branch so a string-view field is emitted as a quoted, escaped JSON string instead of a bare token that produces invalid JSON. Sizes data_capacity from value_offsets first/last rather than value_data().len() so a sliced input does not over-allocate. Adds five tests: float NaN/Infinity quoting, string escaping (quote/newline/tab/backslash), non-ASCII passthrough, ignore_null_fields=false, and Utf8View field quoting/escaping.
|
Thanks for the careful read @mbutrovich. Addressed in 2a3c5b5:
|
Which issue does this PR close?
N/A
Rationale for this change
Optimize
struct_to_jsonon the hot per-row path.What changes are included in this PR?
"field_name":once per column so each field costs a single copy rather than one push per punctuation character.Quotedfor Utf8/LargeUtf8/Utf8View,Rawwhen the rendering can never beNaN/Infinity,MaybeQuotedotherwise) so the per-valueis_infinity/is_nancheck is skipped on types like ints, decimals, and timestamps.StringBuilder(Writeimpl) via a smallappendhelper instead of staging each row in a temporaryString.value_databuffer) so sliced inputs do not over-allocate.Utf8Viewfields were falling through to the unquoted branch (pre-existing bug); they are now quoted and escaped likeUtf8/LargeUtf8.NaN/Infinity, string escaping (",\n,\t,\\), non-ASCII passthrough,ignore_null_fields=false, andUtf8Viewfield quoting.Follow-up: adding a
to_jsoncriterion bench (there isn't one in-tree today is tracked separately.How are these changes tested?
Existing tests plus five new unit tests listed above.
EOF
)