8000 AGTMETRICS-61 Optimize utf-8 encoding of payloads by vickenty · Pull Request #263 · DataDog/java-dogstatsd-client · GitHub
[go: up one dir, main page]

Skip to content

AGTMETRICS-61 Optimize utf-8 encoding of payloads #263

New issue 8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 27, 2025
Merged

Conversation

vickenty
Copy link
Contributor

Optimize client UTF-8 encoding with hand-rolled conversion from UTF-16.

For pure ascii strings, this is much faster than using CharsetEncoder the way we were using it (A: 4.4.3, B: this PR).
Screenshot 2025-03-26 at 20 04 38

While the encoding routine itself is slower, overall it runs on par with String.getBytes due to fewer allocations and less GC pressure (A: #259, B: this PR)
Screenshot 2025-03-26 at 20 14 22

With a few non-ascii characters, it is a bit slower, but still outperforms CharsetEncoder.
Screenshot 2025-03-26 at 20 18 21

vs String.getBytes()
Screenshot 2025-03-26 at 20 18 28

Use hand-rolled UTF-16 conversion to UTF-8. This is always faster than
using CharsetEncoder. String.getBytes is even faster, but it allocates
and leads to memory usage regression on the test app.
StringBuilder.append(Long) allocates a temporary string, while
StringBuilder.append(long) does not and writes digits directly.
@vickenty vickenty mentioned this pull request Mar 27, 2025
@vickenty vickenty marked this pull request as ready for review March 27, 2025 15:11
@vickenty vickenty requested a review from a team as a code owner March 27, 2025 15:11
@vickenty vickenty merged commit a1b09cc into master Mar 27, 2025
8 checks passed
@vickenty vickenty deleted the vickenty/utfopt branch March 27, 2025 16:02
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
0