Skip to content

perf: optimize struct_to_json (10% faster)#4927

Open
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/struct_to_json-datafusion-comet-20260714-132011
Open

perf: optimize struct_to_json (10% faster)#4927
andygrove wants to merge 1 commit into
apache:mainfrom
andygrove:auto-opt/struct_to_json-datafusion-comet-20260714-132011

Conversation

@andygrove

@andygrove andygrove commented Jul 14, 2026

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

Optimize existing expression.

What changes are included in this PR?

Build to_json rows directly in the StringBuilder with pre-rendered field prefixes, a right-sized buffer, and a single vectorizable column-wide escape scan replacing the per-value byte scan.

How are these changes tested?

Existing tests.

Benchmark (criterion):

  • to_json: 9.92% faster (base 353519ns -> cand 318450ns)

Full criterion output:

to_json                 time:   [316.38 µs 316.78 µs 317.25 µs]
                        change: [−10.245% −9.9200% −9.6049%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 7 outliers among 100 measurements (7.00%)
  1 (1.00%) low mild
  6 (6.00%) high mild

@andygrove andygrove changed the title perf: optimize struct_to_json in datafusion-comet-spark-expr perf: optimize struct_to_json (10% faster) Jul 14, 2026
@andygrove andygrove marked this pull request as ready for review July 14, 2026 19:56
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