cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aleksey Yeschenko (Jira)" <>
Subject [jira] [Commented] (CASSANDRA-15410) Avoid over-allocation of bytes for UTF8 string serialization
Date Thu, 14 Nov 2019 13:23:00 GMT


Aleksey Yeschenko commented on CASSANDRA-15410:

I welcome this change in principle, but it makes me feel a little uneasy. Specifically, it
relies implicitly on how the method is used two levels of abstraction up, and feels slightly
brittle to me.

I wonder if you'd be open instead to a slightly less efficient but, importantly, still resize-avoiding
alternative: modify {{CBUtil#writeString()}} (and {{CBUtil#writeLongString()}} while at it,
just for consistency sake) to explicitly calculate the precise size of encoded string using
{{TypeSizes#encodedUTF8Length()}} method, and then pass that value to {{ByteBufUtil#reserveAndWriteUtf8()}}.
This way, yes, you would effectively calculate the size of the string twice, but the abstraction
won't leak assumptions, and will still avoid unnecessary resizing.

> Avoid over-allocation of bytes for UTF8 string serialization 
> -------------------------------------------------------------
>                 Key: CASSANDRA-15410
>                 URL:
>             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

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message