[
https://issues.apache.org/jira/browse/CASSANDRA-15410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16976776#comment-16976776
]
Yifan Cai commented on CASSANDRA-15410:
---------------------------------------
Updated the PR with the {{sizeOfAsciiString()}} method.
Since the input of the method is a US-ASCII string, the method simply returns
{{2 (size) + str.length}}. Therefore, 2 orders of magnitude faster than
{{sizeOfString()}} that iterates through the string.
{code:java}
[java] Benchmark Mode Cnt
Score Error Units
[java] StringsEncodeBench.sizeOfAsciiString avgt 6
1.999 ± 0.153 ns/op
[java] StringsEncodeBench.sizeOfString avgt 6
283.413 ± 24.614 ns/op
{code}
> Avoid over-allocation of bytes for UTF8 string serialization
> -------------------------------------------------------------
>
> Key: CASSANDRA-15410
> URL: https://issues.apache.org/jira/browse/CASSANDRA-15410
> Project: Cassandra
> Issue Type: Improvement
> Components: Messaging/Client
> Reporter: Yifan Cai
> Assignee: Yifan Cai
> Priority: Normal
> Fix For: 4.0
>
>
> In the current message encoding implementation, it first calculates the
> `encodeSize` and allocates the bytebuffer with that size.
> However, during encoding, it assumes the worst case of writing UTF8 string to
> allocate bytes, i.e. assuming each letter takes 3 bytes.
> The over-estimation further leads to resizing the underlying array and data
> copy.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]