[
https://issues.apache.org/jira/browse/CASSANDRA-15410?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16975077#comment-16975077
]
Aleksey Yeschenko commented on CASSANDRA-15410:
-----------------------------------------------
I don't want to trust {{encodedSize()}} implementations, really (we had
mismatch bugs in those calculations before).
Now, if you inspect the usages of {{CBUtil#writeString()}} you'll notice that
absolute most of those calls are performed strictly on ASCII strings. Keyspace
names, table names, type names, function names, field names, enums - that can
*only* be ASCII due to our grammar limitations.
Of the strings in messages C* server writes - majority being in
{{ResultSet.ResultMetadata}} - none of the strings ever go beyond ASCII. So we
could introduce a special-case {{CBUtil#writeASCIIString()}} to use
{{ByteBufUtil#writeAscii()}} and use that throughout, that should resolve the
issue. And you'll get a further speed bump from the loop removal in ascii
string size calculation in all the {{encodedSize()}} methods.
> 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]