[
https://issues.apache.org/jira/browse/CASSANDRA-15215?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17444639#comment-17444639
]
Aleksandr Sorokoumov commented on CASSANDRA-15215:
--------------------------------------------------
I implemented {{DataOutputPlus#writeBytes}} and added benchmarks that use the
{{DataOutputPlus}} version of the method.
The register approach definitely improves write throughput. Due to increased
number of benchmarks, I also added a visualization for megamorphic calls in
addition to the raw results. "Multiple writes" below refers to the initial
approach I tried with switch-cases for different number of bytes.
I am going to apply the same register approach to reads next.
!writeUnsignedVInt_megamorphic_DOP.png|width=800!
!writeUnsignedVInt_megamorphic_BB.png|width=800!
h4. Register
{noformat}
Benchmark (allocation) Mode Cnt Score
Error Units
VIntCodingBench.testComputeUnsignedVIntSize monomorphic avgt 15 15.939 ±
0.235 ns/op
VIntCodingBench.testComputeUnsignedVIntSize bimorphic avgt 15 15.972 ±
0.170 ns/op
VIntCodingBench.testComputeUnsignedVIntSize megamorphic avgt 15 15.976 ±
0.225 ns/op
VIntCodingBench.testWrite1ByteBB monomorphic avgt 15 9.555 ±
0.059 ns/op
VIntCodingBench.testWrite1ByteBB bimorphic avgt 15 16.777 ±
0.107 ns/op
VIntCodingBench.testWrite1ByteBB megamorphic avgt 15 18.286 ±
0.155 ns/op
VIntCodingBench.testWrite1ByteDOP monomorphic avgt 15 10.507 ±
0.522 ns/op
VIntCodingBench.testWrite1ByteDOP bimorphic avgt 15 19.048 ±
0.262 ns/op
VIntCodingBench.testWrite1ByteDOP megamorphic avgt 15 19.339 ±
0.155 ns/op
VIntCodingBench.testWrite2BytesBB monomorphic avgt 15 14.688 ±
0.170 ns/op
VIntCodingBench.testWrite2BytesBB bimorphic avgt 15 19.421 ±
0.115 ns/op
VIntCodingBench.testWrite2BytesBB megamorphic avgt 15 21.975 ±
0.110 ns/op
VIntCodingBench.testWrite2BytesDOP monomorphic avgt 15 14.675 ±
0.102 ns/op
VIntCodingBench.testWrite2BytesDOP bimorphic avgt 15 22.644 ±
0.217 ns/op
VIntCodingBench.testWrite2BytesDOP megamorphic avgt 15 22.789 ±
0.854 ns/op
VIntCodingBench.testWrite3BytesBB monomorphic avgt 15 14.764 ±
0.112 ns/op
VIntCodingBench.testWrite3BytesBB bimorphic avgt 15 19.543 ±
0.363 ns/op
VIntCodingBench.testWrite3BytesBB megamorphic avgt 15 22.054 ±
0.138 ns/op
VIntCodingBench.testWrite3BytesDOP monomorphic avgt 15 14.706 ±
0.115 ns/op
VIntCodingBench.testWrite3BytesDOP bimorphic avgt 15 22.549 ±
0.151 ns/op
VIntCodingBench.testWrite3BytesDOP megamorphic avgt 15 22.560 ±
0.370 ns/op
VIntCodingBench.testWrite4BytesBB monomorphic avgt 15 14.679 ±
0.158 ns/op
VIntCodingBench.testWrite4BytesBB bimorphic avgt 15 19.593 ±
0.254 ns/op
VIntCodingBench.testWrite4BytesBB megamorphic avgt 15 22.202 ±
0.194 ns/op
VIntCodingBench.testWrite4BytesDOP monomorphic avgt 15 14.669 ±
0.098 ns/op
VIntCodingBench.testWrite4BytesDOP bimorphic avgt 15 22.469 ±
0.195 ns/op
VIntCodingBench.testWrite4BytesDOP megamorphic avgt 15 22.681 ±
0.643 ns/op
VIntCodingBench.testWrite5BytesBB monomorphic avgt 15 14.655 ±
0.142 ns/op
VIntCodingBench.testWrite5BytesBB bimorphic avgt 15 19.390 ±
0.100 ns/op
VIntCodingBench.testWrite5BytesBB megamorphic avgt 15 22.086 ±
0.185 ns/op
VIntCodingBench.testWrite5BytesDOP monomorphic avgt 15 14.668 ±
0.137 ns/op
VIntCodingBench.testWrite5BytesDOP bimorphic avgt 15 22.833 ±
0.615 ns/op
VIntCodingBench.testWrite5BytesDOP megamorphic avgt 15 22.127 ±
0.298 ns/op
VIntCodingBench.testWrite6BytesBB monomorphic avgt 15 14.766 ±
0.252 ns/op
VIntCodingBench.testWrite6BytesBB bimorphic avgt 15 19.502 ±
0.128 ns/op
VIntCodingBench.testWrite6BytesBB megamorphic avgt 15 22.386 ±
0.314 ns/op
VIntCodingBench.testWrite6BytesDOP monomorphic avgt 15 14.690 ±
0.122 ns/op
VIntCodingBench.testWrite6BytesDOP bimorphic avgt 15 22.543 ±
0.200 ns/op
VIntCodingBench.testWrite6BytesDOP megamorphic avgt 15 22.278 ±
0.469 ns/op
VIntCodingBench.testWrite7BytesBB monomorphic avgt 15 14.687 ±
0.268 ns/op
VIntCodingBench.testWrite7BytesBB bimorphic avgt 15 19.434 ±
0.179 ns/op
VIntCodingBench.testWrite7BytesBB megamorphic avgt 15 21.991 ±
0.160 ns/op
VIntCodingBench.testWrite7BytesDOP monomorphic avgt 15 14.677 ±
0.131 ns/op
VIntCodingBench.testWrite7BytesDOP bimorphic avgt 15 22.819 ±
0.553 ns/op
VIntCodingBench.testWrite7BytesDOP megamorphic avgt 15 22.893 ±
0.736 ns/op
VIntCodingBench.testWrite8BytesBB monomorphic avgt 15 13.047 ±
0.072 ns/op
VIntCodingBench.testWrite8BytesBB bimorphic avgt 15 17.629 ±
0.192 ns/op
VIntCodingBench.testWrite8BytesBB megamorphic avgt 15 20.674 ±
0.216 ns/op
VIntCodingBench.testWrite8BytesDOP monomorphic avgt 15 14.785 ±
0.316 ns/op
VIntCodingBench.testWrite8BytesDOP bimorphic avgt 15 22.605 ±
0.143 ns/op
VIntCodingBench.testWrite8BytesDOP megamorphic avgt 15 22.411 ±
0.907 ns/op
VIntCodingBench.testWrite9BytesBB monomorphic avgt 15 14.495 ±
0.123 ns/op
VIntCodingBench.testWrite9BytesBB bimorphic avgt 15 20.330 ±
1.697 ns/op
VIntCodingBench.testWrite9BytesBB megamorphic avgt 15 22.011 ±
0.637 ns/op
VIntCodingBench.testWrite9BytesDOP monomorphic avgt 15 13.706 ±
0.089 ns/op
VIntCodingBench.testWrite9BytesDOP bimorphic avgt 15 21.891 ±
0.435 ns/op
VIntCodingBench.testWrite9BytesDOP megamorphic avgt 15 22.970 ±
0.246 ns/op
VIntCodingBench.testWriteRandomLongBB monomorphic avgt 15 26.456 ±
0.536 ns/op
VIntCodingBench.testWriteRandomLongBB bimorphic avgt 15 32.810 ±
0.580 ns/op
VIntCodingBench.testWriteRandomLongBB megamorphic avgt 15 32.634 ±
0.602 ns/op
VIntCodingBench.testWriteRandomLongDOP monomorphic avgt 15 26.408 ±
0.988 ns/op
VIntCodingBench.testWriteRandomLongDOP bimorphic avgt 15 32.097 ±
2.057 ns/op
VIntCodingBench.testWriteRandomLongDOP megamorphic avgt 15 34.598 ±
1.319 ns/op
{noformat}
h4. Multiple writes
{noformat}
Benchmark (allocation) Mode Cnt Score
Error Units
VIntCodingBench.testComputeUnsignedVIntSize monomorphic avgt 15 17.127 ±
0.709 ns/op
VIntCodingBench.testComputeUnsignedVIntSize bimorphic avgt 15 17.389 ±
1.306 ns/op
VIntCodingBench.testComputeUnsignedVIntSize megamorphic avgt 15 16.287 ±
0.481 ns/op
VIntCodingBench.testWrite1ByteBB monomorphic avgt 15 9.417 ±
0.284 ns/op
VIntCodingBench.testWrite1ByteBB bimorphic avgt 15 17.806 ±
0.589 ns/op
VIntCodingBench.testWrite1ByteBB megamorphic avgt 15 18.623 ±
0.787 ns/op
VIntCodingBench.testWrite1ByteDOP monomorphic avgt 15 13.974 ±
0.576 ns/op
VIntCodingBench.testWrite1ByteDOP bimorphic avgt 15 22.223 ±
0.883 ns/op
VIntCodingBench.testWrite1ByteDOP megamorphic avgt 15 23.301 ±
0.685 ns/op
VIntCodingBench.testWrite2BytesBB monomorphic avgt 15 9.537 ±
0.314 ns/op
VIntCodingBench.testWrite2BytesBB bimorphic avgt 15 17.371 ±
0.472 ns/op
VIntCodingBench.testWrite2BytesBB megamorphic avgt 15 18.636 ±
0.539 ns/op
VIntCodingBench.testWrite2BytesDOP monomorphic avgt 15 14.921 ±
0.661 ns/op
VIntCodingBench.testWrite2BytesDOP bimorphic avgt 15 22.561 ±
0.448 ns/op
VIntCodingBench.testWrite2BytesDOP megamorphic avgt 15 24.397 ±
0.745 ns/op
VIntCodingBench.testWrite3BytesBB monomorphic avgt 15 11.220 ±
0.337 ns/op
VIntCodingBench.testWrite3BytesBB bimorphic avgt 15 19.180 ±
0.398 ns/op
VIntCodingBench.testWrite3BytesBB megamorphic avgt 15 20.009 ±
0.592 ns/op
VIntCodingBench.testWrite3BytesDOP monomorphic avgt 15 16.094 ±
0.481 ns/op
VIntCodingBench.testWrite3BytesDOP bimorphic avgt 15 25.855 ±
0.873 ns/op
VIntCodingBench.testWrite3BytesDOP megamorphic avgt 15 26.087 ±
0.735 ns/op
VIntCodingBench.testWrite4BytesBB monomorphic avgt 15 10.252 ±
0.344 ns/op
VIntCodingBench.testWrite4BytesBB bimorphic avgt 15 18.760 ±
2.626 ns/op
VIntCodingBench.testWrite4BytesBB megamorphic avgt 15 19.677 ±
0.642 ns/op
VIntCodingBench.testWrite4BytesDOP monomorphic avgt 15 15.099 ±
0.317 ns/op
VIntCodingBench.testWrite4BytesDOP bimorphic avgt 15 22.329 ±
0.629 ns/op
VIntCodingBench.testWrite4BytesDOP megamorphic avgt 15 25.075 ±
0.973 ns/op
VIntCodingBench.testWrite5BytesBB monomorphic avgt 15 10.561 ±
0.354 ns/op
VIntCodingBench.testWrite5BytesBB bimorphic avgt 15 18.056 ±
0.582 ns/op
VIntCodingBench.testWrite5BytesBB megamorphic avgt 15 19.491 ±
0.598 ns/op
VIntCodingBench.testWrite5BytesDOP monomorphic avgt 15 16.228 ±
0.480 ns/op
VIntCodingBench.testWrite5BytesDOP bimorphic avgt 15 24.403 ±
0.744 ns/op
VIntCodingBench.testWrite5BytesDOP megamorphic avgt 15 25.119 ±
0.904 ns/op
VIntCodingBench.testWrite6BytesBB monomorphic avgt 15 12.688 ±
0.388 ns/op
VIntCodingBench.testWrite6BytesBB bimorphic avgt 15 19.904 ±
0.730 ns/op
VIntCodingBench.testWrite6BytesBB megamorphic avgt 15 21.964 ±
0.772 ns/op
VIntCodingBench.testWrite6BytesDOP monomorphic avgt 15 17.678 ±
0.797 ns/op
VIntCodingBench.testWrite6BytesDOP bimorphic avgt 15 24.909 ±
1.068 ns/op
VIntCodingBench.testWrite6BytesDOP megamorphic avgt 15 28.334 ±
0.732 ns/op
VIntCodingBench.testWrite7BytesBB monomorphic avgt 15 12.502 ±
0.410 ns/op
VIntCodingBench.testWrite7BytesBB bimorphic avgt 15 20.105 ±
0.653 ns/op
VIntCodingBench.testWrite7BytesBB megamorphic avgt 15 23.053 ±
0.923 ns/op
VIntCodingBench.testWrite7BytesDOP monomorphic avgt 15 18.053 ±
1.386 ns/op
VIntCodingBench.testWrite7BytesDOP bimorphic avgt 15 27.000 ±
0.889 ns/op
VIntCodingBench.testWrite7BytesDOP megamorphic avgt 15 30.684 ±
1.024 ns/op
VIntCodingBench.testWrite8BytesBB monomorphic avgt 15 12.383 ±
0.630 ns/op
VIntCodingBench.testWrite8BytesBB bimorphic avgt 15 19.600 ±
0.543 ns/op
VIntCodingBench.testWrite8BytesBB megamorphic avgt 15 20.995 ±
0.918 ns/op
VIntCodingBench.testWrite8BytesDOP monomorphic avgt 15 16.830 ±
0.372 ns/op
VIntCodingBench.testWrite8BytesDOP bimorphic avgt 15 25.022 ±
0.615 ns/op
VIntCodingBench.testWrite8BytesDOP megamorphic avgt 15 25.871 ±
0.845 ns/op
VIntCodingBench.testWrite9BytesBB monomorphic avgt 15 12.396 ±
0.604 ns/op
VIntCodingBench.testWrite9BytesBB bimorphic avgt 15 20.006 ±
0.586 ns/op
VIntCodingBench.testWrite9BytesBB megamorphic avgt 15 22.612 ±
0.670 ns/op
VIntCodingBench.testWrite9BytesDOP monomorphic avgt 15 18.393 ±
0.587 ns/op
VIntCodingBench.testWrite9BytesDOP bimorphic avgt 15 24.908 ±
0.714 ns/op
VIntCodingBench.testWrite9BytesDOP megamorphic avgt 15 29.258 ±
1.792 ns/op
VIntCodingBench.testWriteRandomLongBB monomorphic avgt 15 25.575 ±
0.933 ns/op
VIntCodingBench.testWriteRandomLongBB bimorphic avgt 15 33.336 ±
0.926 ns/op
VIntCodingBench.testWriteRandomLongBB megamorphic avgt 15 34.463 ±
2.112 ns/op
VIntCodingBench.testWriteRandomLongDOP monomorphic avgt 15 29.358 ±
0.785 ns/op
VIntCodingBench.testWriteRandomLongDOP bimorphic avgt 15 34.367 ±
1.122 ns/op
VIntCodingBench.testWriteRandomLongDOP megamorphic avgt 15 36.373 ±
0.995 ns/op
{noformat}
h4. Baseline
{noformat}
Benchmark (allocation) Mode Cnt Score
Error Units
VIntCodingBench.testComputeUnsignedVIntSize monomorphic avgt 15 16.237 ±
0.144 ns/op
VIntCodingBench.testComputeUnsignedVIntSize bimorphic avgt 15 16.273 ±
0.193 ns/op
VIntCodingBench.testComputeUnsignedVIntSize megamorphic avgt 15 16.251 ±
0.226 ns/op
VIntCodingBench.testWrite1ByteBB monomorphic avgt 15 8.722 ±
0.049 ns/op
VIntCodingBench.testWrite1ByteBB bimorphic avgt 15 17.095 ±
0.656 ns/op
VIntCodingBench.testWrite1ByteBB megamorphic avgt 15 17.856 ±
0.366 ns/op
VIntCodingBench.testWrite1ByteDOP monomorphic avgt 15 10.539 ±
0.304 ns/op
VIntCodingBench.testWrite1ByteDOP bimorphic avgt 15 19.000 ±
0.229 ns/op
VIntCodingBench.testWrite1ByteDOP megamorphic avgt 15 19.755 ±
0.332 ns/op
VIntCodingBench.testWrite2BytesBB monomorphic avgt 15 19.322 ±
0.125 ns/op
VIntCodingBench.testWrite2BytesBB bimorphic avgt 15 25.739 ±
0.445 ns/op
VIntCodingBench.testWrite2BytesBB megamorphic avgt 15 29.106 ±
0.706 ns/op
VIntCodingBench.testWrite2BytesDOP monomorphic avgt 15 25.940 ±
0.161 ns/op
VIntCodingBench.testWrite2BytesDOP bimorphic avgt 15 33.446 ±
0.527 ns/op
VIntCodingBench.testWrite2BytesDOP megamorphic avgt 15 37.912 ±
1.958 ns/op
VIntCodingBench.testWrite3BytesBB monomorphic avgt 15 22.309 ±
2.962 ns/op
VIntCodingBench.testWrite3BytesBB bimorphic avgt 15 26.560 ±
0.684 ns/op
VIntCodingBench.testWrite3BytesBB megamorphic avgt 15 30.398 ±
0.843 ns/op
VIntCodingBench.testWrite3BytesDOP monomorphic avgt 15 27.975 ±
1.135 ns/op
VIntCodingBench.testWrite3BytesDOP bimorphic avgt 15 34.763 ±
0.654 ns/op
VIntCodingBench.testWrite3BytesDOP megamorphic avgt 15 39.441 ±
0.284 ns/op
VIntCodingBench.testWrite4BytesBB monomorphic avgt 15 21.715 ±
0.365 ns/op
VIntCodingBench.testWrite4BytesBB bimorphic avgt 15 28.755 ±
0.317 ns/op
VIntCodingBench.testWrite4BytesBB megamorphic avgt 15 31.959 ±
0.522 ns/op
VIntCodingBench.testWrite4BytesDOP monomorphic avgt 15 27.525 ±
0.526 ns/op
VIntCodingBench.testWrite4BytesDOP bimorphic avgt 15 36.992 ±
0.201 ns/op
VIntCodingBench.testWrite4BytesDOP megamorphic avgt 15 39.074 ±
0.808 ns/op
VIntCodingBench.testWrite5BytesBB monomorphic avgt 15 21.620 ±
0.509 ns/op
VIntCodingBench.testWrite5BytesBB bimorphic avgt 15 27.592 ±
0.259 ns/op
VIntCodingBench.testWrite5BytesBB megamorphic avgt 15 31.718 ±
0.809 ns/op
VIntCodingBench.testWrite5BytesDOP monomorphic avgt 15 26.949 ±
0.189 ns/op
VIntCodingBench.testWrite5BytesDOP bimorphic avgt 15 34.916 ±
0.386 ns/op
VIntCodingBench.testWrite5BytesDOP megamorphic avgt 15 39.920 ±
1.518 ns/op
VIntCodingBench.testWrite6BytesBB monomorphic avgt 15 21.572 ±
0.435 ns/op
VIntCodingBench.testWrite6BytesBB bimorphic avgt 15 28.094 ±
0.450 ns/op
VIntCodingBench.testWrite6BytesBB megamorphic avgt 15 32.456 ±
0.488 ns/op
VIntCodingBench.testWrite6BytesDOP monomorphic avgt 15 27.655 ±
0.453 ns/op
VIntCodingBench.testWrite6BytesDOP bimorphic avgt 15 39.025 ±
0.517 ns/op
VIntCodingBench.testWrite6BytesDOP megamorphic avgt 15 39.899 ±
1.011 ns/op
VIntCodingBench.testWrite7BytesBB monomorphic avgt 15 21.973 ±
0.426 ns/op
VIntCodingBench.testWrite7BytesBB bimorphic avgt 15 27.559 ±
0.316 ns/op
VIntCodingBench.testWrite7BytesBB megamorphic avgt 15 31.988 ±
0.373 ns/op
VIntCodingBench.testWrite7BytesDOP monomorphic avgt 15 28.257 ±
0.205 ns/op
VIntCodingBench.testWrite7BytesDOP bimorphic avgt 15 37.111 ±
0.625 ns/op
VIntCodingBench.testWrite7BytesDOP megamorphic avgt 15 38.689 ±
0.214 ns/op
VIntCodingBench.testWrite8BytesBB monomorphic avgt 15 23.458 ±
0.456 ns/op
VIntCodingBench.testWrite8BytesBB bimorphic avgt 15 28.696 ±
0.137 ns/op
VIntCodingBench.testWrite8BytesBB megamorphic avgt 15 32.025 ±
0.448 ns/op
VIntCodingBench.testWrite8BytesDOP monomorphic avgt 15 28.777 ±
0.374 ns/op
VIntCodingBench.testWrite8BytesDOP bimorphic avgt 15 37.232 ±
0.374 ns/op
VIntCodingBench.testWrite8BytesDOP megamorphic avgt 15 39.832 ±
0.825 ns/op
VIntCodingBench.testWrite9BytesBB monomorphic avgt 15 22.873 ±
1.074 ns/op
VIntCodingBench.testWrite9BytesBB bimorphic avgt 15 28.377 ±
0.501 ns/op
VIntCodingBench.testWrite9BytesBB megamorphic avgt 15 31.409 ±
0.611 ns/op
VIntCodingBench.testWrite9BytesDOP monomorphic avgt 15 29.532 ±
1.390 ns/op
VIntCodingBench.testWrite9BytesDOP bimorphic avgt 15 39.124 ±
3.493 ns/op
VIntCodingBench.testWrite9BytesDOP megamorphic avgt 15 39.400 ±
0.439 ns/op
VIntCodingBench.testWriteRandomLongBB monomorphic avgt 15 34.258 ±
0.192 ns/op
VIntCodingBench.testWriteRandomLongBB bimorphic avgt 15 43.513 ±
0.411 ns/op
VIntCodingBench.testWriteRandomLongBB megamorphic avgt 15 42.713 ±
0.514 ns/op
VIntCodingBench.testWriteRandomLongDOP monomorphic avgt 15 38.191 ±
0.280 ns/op
VIntCodingBench.testWriteRandomLongDOP bimorphic avgt 15 48.820 ±
0.327 ns/op
VIntCodingBench.testWriteRandomLongDOP megamorphic avgt 15 51.459 ±
0.399 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
> Assignee: Aleksandr Sorokoumov
> Priority: Normal
> Fix For: 3.0.x, 3.11.x, 4.x
>
> Attachments: writeUnsignedVInt_megamorphic_BB.png,
> writeUnsignedVInt_megamorphic_DOP.png
>
>
> 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.20.1#820001)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]