[ 
https://issues.apache.org/jira/browse/CASSANDRA-15215?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17436519#comment-17436519
 ] 

Aleksandr Sorokoumov commented on CASSANDRA-15215:
--------------------------------------------------

[~benedict] if I understood your idea correctly, you suggest writing relevant 
bytes directly instead of preparing the thread-local byte array and memcpy'ing 
it into the given buffer. Is my interpretation correct? In the title and 
description you also mentioned reads, but I haven't figured how to adjust this 
idea there, so here are results for writes only.

h2. Code
||Branch||Description||
|[baseline|https://github.com/apache/cassandra/compare/trunk...Gerrrr:15215-baseline-trunk?expand=1]|trunk
 + benchmark|
|[patch|https://github.com/apache/cassandra/compare/trunk...Gerrrr:15215-trunk?expand=1]|patch
 + benchmark|
h2. Setup

Each benchmark does {{VIntCoding.writeUnsignedVInt}} on a {{long}} from 1 to 9 
bytes. The write target is a {{ByteBuffer}} - both on- and off- heap.

The results are produced on a MBP 2019 - 2,3 GHz 8-Core Intel Core i9.
h2. Results
h3. Baseline
{noformat}
Benchmark                        (allocation)  Mode  Cnt   Score   Error  Units
VIntCodingBench.testWrite1Byte           HEAP  avgt   15   9.084 ± 5.196  ns/op
VIntCodingBench.testWrite1Byte         DIRECT  avgt   15   5.037 ± 0.638  ns/op
VIntCodingBench.testWrite2Bytes          HEAP  avgt   15  15.604 ± 0.646  ns/op
VIntCodingBench.testWrite2Bytes        DIRECT  avgt   15  15.028 ± 0.568  ns/op
VIntCodingBench.testWrite3Bytes          HEAP  avgt   15  16.704 ± 0.461  ns/op
VIntCodingBench.testWrite3Bytes        DIRECT  avgt   15  17.410 ± 0.489  ns/op
VIntCodingBench.testWrite4Bytes          HEAP  avgt   15  17.086 ± 0.527  ns/op
VIntCodingBench.testWrite4Bytes        DIRECT  avgt   15  20.307 ± 0.705  ns/op
VIntCodingBench.testWrite5Bytes          HEAP  avgt   15  17.395 ± 0.578  ns/op
VIntCodingBench.testWrite5Bytes        DIRECT  avgt   15  17.558 ± 0.512  ns/op
VIntCodingBench.testWrite6Bytes          HEAP  avgt   15  18.114 ± 0.967  ns/op
VIntCodingBench.testWrite6Bytes        DIRECT  avgt   15  19.023 ± 0.591  ns/op
VIntCodingBench.testWrite7Bytes          HEAP  avgt   15  18.004 ± 0.298  ns/op
VIntCodingBench.testWrite7Bytes        DIRECT  avgt   15  19.081 ± 0.601  ns/op
VIntCodingBench.testWrite8Bytes          HEAP  avgt   15  18.466 ± 0.463  ns/op
VIntCodingBench.testWrite8Bytes        DIRECT  avgt   15  20.228 ± 5.620  ns/op
VIntCodingBench.testWrite9Bytes          HEAP  avgt   15  18.553 ± 0.537  ns/op
VIntCodingBench.testWrite9Bytes        DIRECT  avgt   15  20.101 ± 0.476  ns/op
{noformat}
h3. Patch
{noformat}
Benchmark                        (allocation)  Mode  Cnt   Score   Error  Units
VIntCodingBench.testWrite1Byte           HEAP  avgt   15   4.728 ± 0.077  ns/op
VIntCodingBench.testWrite1Byte         DIRECT  avgt   15   6.415 ± 3.157  ns/op
VIntCodingBench.testWrite2Bytes          HEAP  avgt   15   8.244 ± 0.440  ns/op
VIntCodingBench.testWrite2Bytes        DIRECT  avgt   15   9.136 ± 3.979  ns/op
VIntCodingBench.testWrite3Bytes          HEAP  avgt   15   8.714 ± 0.134  ns/op
VIntCodingBench.testWrite3Bytes        DIRECT  avgt   15   9.690 ± 2.735  ns/op
VIntCodingBench.testWrite4Bytes          HEAP  avgt   15   8.634 ± 0.164  ns/op
VIntCodingBench.testWrite4Bytes        DIRECT  avgt   15   6.830 ± 0.061  ns/op
VIntCodingBench.testWrite5Bytes          HEAP  avgt   15   8.389 ± 0.207  ns/op
VIntCodingBench.testWrite5Bytes        DIRECT  avgt   15   8.059 ± 1.537  ns/op
VIntCodingBench.testWrite6Bytes          HEAP  avgt   15  10.861 ± 0.336  ns/op
VIntCodingBench.testWrite6Bytes        DIRECT  avgt   15   9.816 ± 1.482  ns/op
VIntCodingBench.testWrite7Bytes          HEAP  avgt   15  11.045 ± 0.419  ns/op
VIntCodingBench.testWrite7Bytes        DIRECT  avgt   15  10.702 ± 2.377  ns/op
VIntCodingBench.testWrite8Bytes          HEAP  avgt   15  10.375 ± 0.423  ns/op
VIntCodingBench.testWrite8Bytes        DIRECT  avgt   15   7.237 ± 0.176  ns/op
VIntCodingBench.testWrite9Bytes          HEAP  avgt   15  11.200 ± 0.365  ns/op
VIntCodingBench.testWrite9Bytes        DIRECT  avgt   15   8.152 ± 0.282  ns/op
{noformat}

> VIntCoding should read and write more efficiently
> -------------------------------------------------
>
>                 Key: CASSANDRA-15215
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-15215
>             Project: Cassandra
>          Issue Type: Bug
>          Components: Local/Compaction, Local/SSTable
>            Reporter: Benedict Elliott Smith
>            Priority: Normal
>             Fix For: 3.0.x, 3.11.x, 4.x
>
>
> Most vints occupy significantly fewer than 8 bytes, and most buffers have >= 
> 8 bytes spare, in which case we can construct the relevant bytes in a 
> register and memcpy them to the correct position.  Since we read and write a 
> lot of vints, this waste is probably measurable, particularly during 
> compaction and flush, and can probably be considered a performance bug.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to