Skip to content

perf: optimize to_json (2x faster)#4902

Merged
andygrove merged 1 commit into
apache:mainfrom
andygrove:auto-opt/escape_string-datafusion-comet-20260712-091032
Jul 13, 2026
Merged

perf: optimize to_json (2x faster)#4902
andygrove merged 1 commit into
apache:mainfrom
andygrove:auto-opt/escape_string-datafusion-comet-20260712-091032

Conversation

@andygrove

@andygrove andygrove commented Jul 12, 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?

escape_string now returns Cow (zero-alloc borrow when nothing needs escaping) and bulk-copies unescaped byte runs instead of allocating and pushing char-by-char per string value in to_json.

How are these changes tested?

Existing tests

Benchmark (criterion):

  • to_json: 56.164% faster (base 757921ns -> cand 332246ns)

@andygrove andygrove changed the title perf: optimize escape_string in datafusion-comet-spark-expr perf: optimize escape_string / to_json Jul 12, 2026
@andygrove andygrove changed the title perf: optimize escape_string / to_json perf: optimize escape_string / to_json (56% faster) Jul 12, 2026
@andygrove andygrove changed the title perf: optimize escape_string / to_json (56% faster) perf: optimize escape_string / to_json (2x faster) Jul 13, 2026
@andygrove andygrove changed the title perf: optimize escape_string / to_json (2x faster) perf: optimize to_json (2x faster) Jul 13, 2026
@andygrove andygrove marked this pull request as ready for review July 13, 2026 16:20

@mbutrovich mbutrovich left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me, thanks @andygrove!

@andygrove andygrove merged commit dd30f41 into apache:main Jul 13, 2026
76 checks passed
@andygrove andygrove deleted the auto-opt/escape_string-datafusion-comet-20260712-091032 branch July 13, 2026 21:24
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.

2 participants