CASSANDRA-15410: Improve strings encoding speed and add benchmarks#382
Closed
yifan-c wants to merge 3 commits intoapache:trunkfrom
Closed
CASSANDRA-15410: Improve strings encoding speed and add benchmarks#382yifan-c wants to merge 3 commits intoapache:trunkfrom
yifan-c wants to merge 3 commits intoapache:trunkfrom
Conversation
c14b6a8 to
df47cd5
Compare
Contributor
Author
|
Based on Aleksey's comment, a new write string method only for ASCII was added. The latest benchmark shows similar performance between |
2373de6 to
471c4f4
Compare
blambov
pushed a commit
to blambov/cassandra
that referenced
this pull request
Jun 13, 2022
(cherry picked from commit 40e0941)
ekaterinadimitrova2
pushed a commit
to ekaterinadimitrova2/cassandra
that referenced
this pull request
Jun 3, 2024
michaelsembwever
pushed a commit
to thelastpickle/cassandra
that referenced
this pull request
Jan 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Given the fact that the
encodeSizewas calculated already when encoding, we can leverage the size and safely reserve the remaining capacity for writing to avoid resizing.A set of benchmarks were taken to show the difference. For the long text, the change halves the string encoding time from 571.9 ns to 216.1 ns. The time is almost halves for the short text as well.
The improvement is because of avoiding the unnecessary resizing and data copy.
ByteBufUtils.writeUtf8. It over-estimates the size of string that causes resizing the buffer.TypeSizes.encodeUTF8Lengthto reserve the exact size of bytes to write.