[
https://issues.apache.org/jira/browse/CASSANDRA-21535?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18099137#comment-18099137
]
Dmitry Konstantinov edited comment on CASSANDRA-21535 at 7/25/26 2:53 PM:
--------------------------------------------------------------------------
[~taejin] thank you for the improvement. Have you checked the cost of mutation
size calculation vs the array copy cost? I have had a kind of a reversed idea
to try: if (based some heuristics) a mutation is small then we can avoid size
calculation and serialize directly into the thread local buffer, copy the
result and get size + serialized value using serialize only call, without
serializedSize invocation ...
was (Author: dnk):
[~taejin] thank you for the improvement. Have you checked the cost of mutation
size calculation vs the array copy cost? I have had a kind of a reversed idea
to try: if (based some heuristics) a mutation is small then we can avoid size
calculation and serialize directly into the thread local buffer, copy the
result and get size + serialized value using serialize only call, without
serializedSize...
> Avoid extra copy for cached Mutation serialization
> --------------------------------------------------
>
> Key: CASSANDRA-21535
> URL: https://issues.apache.org/jira/browse/CASSANDRA-21535
> Project: Apache Cassandra
> Issue Type: Improvement
> Reporter: koo
> Priority: Normal
>
> Description
> In Mutation.Serializer.serialization(), we first calculate the serialized
> size.
> After that, current code serializes the mutation to a thread local
> DataOutputBuffer.
> Then unsafeToByteArray() creates a new byte array and copies all serialized
> bytes.
> The serialized size is already known.
> So we can create a fixed size heap buffer first and serialize directly to
> that buffer.
> This change removes one full byte array copy when we create a cached mutation
> serialization.
> I also added a check that the written size is same as the calculated
> serialized size.
> Benchmark
> I added a JMH benchmark for this case.
> For every benchmark operation:
> - clear cached serialization
> - serialize the Mutation
> - create cached serialization again
> JDK 17, arm64, 1 thread:
> | Value size | Before | After | Result |
> |---:|---:|---:|---:|
> | 128 B | 3.70 M ops/s | 3.87 M ops/s | +4% |
> | 16 KiB | 608 K ops/s | 716 K ops/s | +18% |
> | 256 KiB | 41.4 K ops/s | 53.1 K ops/s | +28% |
> | 768 KiB | 6.83 K ops/s | 18.88 K ops/s | +177% |
>
> The result is bigger for large mutations because current code writes the data
> to a
> direct buffer first, and then copies all data again to a heap byte array.
> With this change, serialization writes directly to the final heap byte array.
> This benchmark measures cache creation cost. It does not mean normal write
> throughput will be 2.77x faster, because normal requests can reuse the cached
> serialization.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]