Skip to content

perf: Use Charset in StringUtils to/fromUtf8. - #20310

Open
gianm wants to merge 1 commit into
apache:masterfrom
gianm:perf-utf8-charset
Open

gianm wants to merge 1 commit into
apache:masterfrom
gianm:perf-utf8-charset

Conversation

@gianm

@gianm gianm commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

There is an old optimization in StringUtils#fromUtf8 and toUtf8 that has outlived its usefulness. Apparently it used to be faster to pass the String charset name rather than a Charset object, but that is no longer the case.

There is an old optimization in StringUtils#fromUtf8 and toUtf8 that
has outlived its usefulness. Apparently it used to be faster to pass the
String charset name rather than a Charset object, but that is no longer
the case.
@gianm

gianm commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

Benchmarks. Not checked in, they're just doing the two alternatives on various lengths of strings.

Benchmark                                    (length)  Mode  Cnt     Score    Error  Units
Utf8CharsetBenchmark.fromUtf8_charsetName           8  avgt   10     9.017 ±  0.040  ns/op
Utf8CharsetBenchmark.fromUtf8_charsetName          64  avgt   10    12.426 ±  0.160  ns/op
Utf8CharsetBenchmark.fromUtf8_charsetName        1024  avgt   10    43.674 ±  0.298  ns/op

Utf8CharsetBenchmark.fromUtf8_charsetObject         8  avgt   10     6.724 ±  0.079  ns/op
Utf8CharsetBenchmark.fromUtf8_charsetObject        64  avgt   10    10.231 ±  0.136  ns/op
Utf8CharsetBenchmark.fromUtf8_charsetObject      1024  avgt   10    41.794 ±  0.448  ns/op

Utf8CharsetBenchmark.toUtf8_charsetName             8  avgt   10    10.255 ±  1.114  ns/op
Utf8CharsetBenchmark.toUtf8_charsetName            64  avgt   10    11.069 ±  0.279  ns/op
Utf8CharsetBenchmark.toUtf8_charsetName          1024  avgt   10    42.732 ±  0.385  ns/op

Utf8CharsetBenchmark.toUtf8_charsetObject           8  avgt   10     3.812 ±  0.063  ns/op
Utf8CharsetBenchmark.toUtf8_charsetObject          64  avgt   10     7.024 ±  0.045  ns/op
Utf8CharsetBenchmark.toUtf8_charsetObject        1024  avgt   10    39.115 ±  0.431  ns/op

@github-actions github-actions Bot added Area - Batch Ingestion Area - Ingestion Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 labels Sep 10, 2026

@FrankChen021 FrankChen021 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🟢 Approval recommended

No actionable issues found in this review. The production change keeps the UTF-8 conversion behavior while using StandardCharsets.UTF_8 directly, and the repository-wide references, surrounding call sites, compatibility guidance, and all changed tests were inspected.

Reviewed 6 of 6 changed files.


This is an automated review by Codex GPT-5.6-Luna(max)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Batch Ingestion Area - Ingestion Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants