Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More efficient parsing of ArraySeq #806

Merged
merged 1 commit into from
Feb 10, 2023

Conversation

plokhotnyuk
Copy link
Contributor

Results from JDK 17 shows speed up from 4% to 35% depending on types of stored values:

Before

[info] Benchmark                                                   (size)   Mode  Cnt       Score       Error   Units
[info] ArrayOfBigDecimalsReading.smithy4sJson                         128  thrpt    5  120905.049 ±  2076.973   ops/s
[info] ArrayOfBigDecimalsReading.smithy4sJson:·gc.alloc.rate          128  thrpt    5    2791.680 ±    48.010  MB/sec
[info] ArrayOfBigDecimalsReading.smithy4sJson:·gc.alloc.rate.norm     128  thrpt    5   24216.004 ±     0.001    B/op
[info] ArrayOfBigDecimalsReading.smithy4sJson:·gc.count               128  thrpt    5      19.000              counts
[info] ArrayOfBigDecimalsReading.smithy4sJson:·gc.time                128  thrpt    5       6.000                  ms
[info] ArrayOfBigIntsReading.smithy4sJson                             128  thrpt    5  182631.331 ±  1006.758   ops/s
[info] ArrayOfBigIntsReading.smithy4sJson:·gc.alloc.rate              128  thrpt    5    3250.054 ±    17.781  MB/sec
[info] ArrayOfBigIntsReading.smithy4sJson:·gc.alloc.rate.norm         128  thrpt    5   18664.002 ±     0.001    B/op
[info] ArrayOfBigIntsReading.smithy4sJson:·gc.count                   128  thrpt    5      21.000              counts
[info] ArrayOfBigIntsReading.smithy4sJson:·gc.time                    128  thrpt    5       6.000                  ms
[info] ArrayOfBooleansReading.smithy4sJson                            128  thrpt    5  849055.664 ± 18008.562   ops/s
[info] ArrayOfBooleansReading.smithy4sJson:·gc.alloc.rate             128  thrpt    5    1165.759 ±    24.677  MB/sec
[info] ArrayOfBooleansReading.smithy4sJson:·gc.alloc.rate.norm        128  thrpt    5    1440.001 ±     0.001    B/op
[info] ArrayOfBooleansReading.smithy4sJson:·gc.count                  128  thrpt    5       8.000              counts
[info] ArrayOfBooleansReading.smithy4sJson:·gc.time                   128  thrpt    5      13.000                  ms
[info] ArrayOfBytesReading.smithy4sJson                               128  thrpt    5  681378.984 ±  6838.489   ops/s
[info] ArrayOfBytesReading.smithy4sJson:·gc.alloc.rate                128  thrpt    5     935.562 ±     9.334  MB/sec
[info] ArrayOfBytesReading.smithy4sJson:·gc.alloc.rate.norm           128  thrpt    5    1440.001 ±     0.001    B/op
[info] ArrayOfBytesReading.smithy4sJson:·gc.count                     128  thrpt    5       6.000              counts
[info] ArrayOfBytesReading.smithy4sJson:·gc.time                      128  thrpt    5      10.000                  ms
[info] ArrayOfDoublesReading.smithy4sJson                             128  thrpt    5  277787.586 ±  3250.322   ops/s
[info] ArrayOfDoublesReading.smithy4sJson:·gc.alloc.rate              128  thrpt    5    1432.430 ±    16.816  MB/sec
[info] ArrayOfDoublesReading.smithy4sJson:·gc.alloc.rate.norm         128  thrpt    5    5408.002 ±     0.001    B/op
[info] ArrayOfDoublesReading.smithy4sJson:·gc.count                   128  thrpt    5       9.000              counts
[info] ArrayOfDoublesReading.smithy4sJson:·gc.time                    128  thrpt    5      13.000                  ms
[info] ArrayOfFloatsReading.smithy4sJson                              128  thrpt    5  360002.552 ±  2947.879   ops/s
[info] ArrayOfFloatsReading.smithy4sJson:·gc.alloc.rate               128  thrpt    5    1337.325 ±    11.014  MB/sec
[info] ArrayOfFloatsReading.smithy4sJson:·gc.alloc.rate.norm          128  thrpt    5    3896.001 ±     0.001    B/op
[info] ArrayOfFloatsReading.smithy4sJson:·gc.count                    128  thrpt    5       9.000              counts
[info] ArrayOfFloatsReading.smithy4sJson:·gc.time                     128  thrpt    5      13.000                  ms
[info] ArrayOfInstantsReading.smithy4sJson                            128  thrpt    5  133326.005 ±  2321.304   ops/s
[info] ArrayOfInstantsReading.smithy4sJson:·gc.alloc.rate             128  thrpt    5    2260.796 ±    39.533  MB/sec
[info] ArrayOfInstantsReading.smithy4sJson:·gc.alloc.rate.norm        128  thrpt    5   17784.008 ±     0.001    B/op
[info] ArrayOfInstantsReading.smithy4sJson:·gc.count                  128  thrpt    5      15.000              counts
[info] ArrayOfInstantsReading.smithy4sJson:·gc.time                   128  thrpt    5       9.000                  ms
[info] ArrayOfIntsReading.smithy4sJson                                128  thrpt    5  462710.404 ±  4093.057   ops/s
[info] ArrayOfIntsReading.smithy4sJson:·gc.alloc.rate                 128  thrpt    5    1475.355 ±    13.126  MB/sec
[info] ArrayOfIntsReading.smithy4sJson:·gc.alloc.rate.norm            128  thrpt    5    3344.001 ±     0.001    B/op
[info] ArrayOfIntsReading.smithy4sJson:·gc.count                      128  thrpt    5       9.000              counts
[info] ArrayOfIntsReading.smithy4sJson:·gc.time                       128  thrpt    5      12.000                  ms
[info] ArrayOfLongsReading.smithy4sJson                               128  thrpt    5  427808.612 ±  5874.468   ops/s
[info] ArrayOfLongsReading.smithy4sJson:·gc.alloc.rate                128  thrpt    5    2068.879 ±    28.411  MB/sec
[info] ArrayOfLongsReading.smithy4sJson:·gc.alloc.rate.norm           128  thrpt    5    5072.001 ±     0.001    B/op
[info] ArrayOfLongsReading.smithy4sJson:·gc.count                     128  thrpt    5      14.000              counts
[info] ArrayOfLongsReading.smithy4sJson:·gc.time                      128  thrpt    5      10.000                  ms
[info] ArrayOfShortsReading.smithy4sJson                              128  thrpt    5  567022.175 ±  3629.408   ops/s
[info] ArrayOfShortsReading.smithy4sJson:·gc.alloc.rate               128  thrpt    5    1392.744 ±     8.969  MB/sec
[info] ArrayOfShortsReading.smithy4sJson:·gc.alloc.rate.norm          128  thrpt    5    2576.001 ±     0.001    B/op
[info] ArrayOfShortsReading.smithy4sJson:·gc.count                    128  thrpt    5       9.000              counts
[info] ArrayOfShortsReading.smithy4sJson:·gc.time                     128  thrpt    5      13.000                  ms
[info] ArrayOfUUIDsReading.smithy4sJson                               128  thrpt    5  370160.788 ±  3422.236   ops/s
[info] ArrayOfUUIDsReading.smithy4sJson:·gc.alloc.rate                128  thrpt    5    2089.384 ±    19.473  MB/sec
[info] ArrayOfUUIDsReading.smithy4sJson:·gc.alloc.rate.norm           128  thrpt    5    5920.001 ±     0.001    B/op
[info] ArrayOfUUIDsReading.smithy4sJson:·gc.count                     128  thrpt    5      13.000              counts
[info] ArrayOfUUIDsReading.smithy4sJson:·gc.time                      128  thrpt    5       9.000                  ms
[info] ArraySeqOfBooleansReading.smithy4sJson                         128  thrpt    5  902632.370 ±  5420.835   ops/s
[info] ArraySeqOfBooleansReading.smithy4sJson:·gc.alloc.rate          128  thrpt    5    1239.323 ±     7.550  MB/sec
[info] ArraySeqOfBooleansReading.smithy4sJson:·gc.alloc.rate.norm     128  thrpt    5    1440.001 ±     0.001    B/op
[info] ArraySeqOfBooleansReading.smithy4sJson:·gc.count               128  thrpt    5       8.000              counts
[info] ArraySeqOfBooleansReading.smithy4sJson:·gc.time                128  thrpt    5      13.000                  ms

After

[info] Benchmark                                                   (size)   Mode  Cnt       Score       Error   Units
[info] ArrayOfBigDecimalsReading.smithy4sJson                         128  thrpt    5  125777.351 ±  1827.330   ops/s
[info] ArrayOfBigDecimalsReading.smithy4sJson:·gc.alloc.rate          128  thrpt    5    2780.319 ±    40.375  MB/sec
[info] ArrayOfBigDecimalsReading.smithy4sJson:·gc.alloc.rate.norm     128  thrpt    5   23184.003 ±     0.001    B/op
[info] ArrayOfBigDecimalsReading.smithy4sJson:·gc.count               128  thrpt    5      19.000              counts
[info] ArrayOfBigDecimalsReading.smithy4sJson:·gc.time                128  thrpt    5       5.000                  ms
[info] ArrayOfBigIntsReading.smithy4sJson                             128  thrpt    5  197539.282 ±   637.286   ops/s
[info] ArrayOfBigIntsReading.smithy4sJson:·gc.alloc.rate              128  thrpt    5    3414.451 ±    10.756  MB/sec
[info] ArrayOfBigIntsReading.smithy4sJson:·gc.alloc.rate.norm         128  thrpt    5   18128.002 ±     0.001    B/op
[info] ArrayOfBigIntsReading.smithy4sJson:·gc.count                   128  thrpt    5      23.000              counts
[info] ArrayOfBigIntsReading.smithy4sJson:·gc.time                    128  thrpt    5       8.000                  ms
[info] ArrayOfBooleansReading.smithy4sJson                            128  thrpt    5  994595.107 ±  4467.965   ops/s
[info] ArrayOfBooleansReading.smithy4sJson:·gc.alloc.rate             128  thrpt    5     523.484 ±     2.346  MB/sec
[info] ArrayOfBooleansReading.smithy4sJson:·gc.alloc.rate.norm        128  thrpt    5     552.000 ±     0.001    B/op
[info] ArrayOfBooleansReading.smithy4sJson:·gc.count                  128  thrpt    5       3.000              counts
[info] ArrayOfBooleansReading.smithy4sJson:·gc.time                   128  thrpt    5       5.000                  ms
[info] ArrayOfBytesReading.smithy4sJson                               128  thrpt    5  664871.102 ± 45655.155   ops/s
[info] ArrayOfBytesReading.smithy4sJson:·gc.alloc.rate                128  thrpt    5     349.928 ±    24.077  MB/sec
[info] ArrayOfBytesReading.smithy4sJson:·gc.alloc.rate.norm           128  thrpt    5     552.001 ±     0.001    B/op
[info] ArrayOfBytesReading.smithy4sJson:·gc.count                     128  thrpt    5       2.000              counts
[info] ArrayOfBytesReading.smithy4sJson:·gc.time                      128  thrpt    5       4.000                  ms
[info] ArrayOfDoublesReading.smithy4sJson                             128  thrpt    5  286731.274 ±  1243.898   ops/s
[info] ArrayOfDoublesReading.smithy4sJson:·gc.alloc.rate              128  thrpt    5    1471.946 ±     6.472  MB/sec
[info] ArrayOfDoublesReading.smithy4sJson:·gc.alloc.rate.norm         128  thrpt    5    5384.002 ±     0.001    B/op
[info] ArrayOfDoublesReading.smithy4sJson:·gc.count                   128  thrpt    5       9.000              counts
[info] ArrayOfDoublesReading.smithy4sJson:·gc.time                    128  thrpt    5      12.000                  ms
[info] ArrayOfFloatsReading.smithy4sJson                              128  thrpt    5  381733.480 ± 32819.690   ops/s
[info] ArrayOfFloatsReading.smithy4sJson:·gc.alloc.rate               128  thrpt    5    1225.869 ±   105.619  MB/sec
[info] ArrayOfFloatsReading.smithy4sJson:·gc.alloc.rate.norm          128  thrpt    5    3368.001 ±     0.001    B/op
[info] ArrayOfFloatsReading.smithy4sJson:·gc.count                    128  thrpt    5       8.000              counts
[info] ArrayOfFloatsReading.smithy4sJson:·gc.time                     128  thrpt    5      13.000                  ms
[info] ArrayOfInstantsReading.smithy4sJson                            128  thrpt    5  139646.036 ±  1693.416   ops/s
[info] ArrayOfInstantsReading.smithy4sJson:·gc.alloc.rate             128  thrpt    5    2294.489 ±    27.904  MB/sec
[info] ArrayOfInstantsReading.smithy4sJson:·gc.alloc.rate.norm        128  thrpt    5   17232.007 ±     0.001    B/op
[info] ArrayOfInstantsReading.smithy4sJson:·gc.count                  128  thrpt    5      15.000              counts
[info] ArrayOfInstantsReading.smithy4sJson:·gc.time                   128  thrpt    5       8.000                  ms
[info] ArrayOfIntsReading.smithy4sJson                                128  thrpt    5  577700.100 ±  3302.313   ops/s
[info] ArrayOfIntsReading.smithy4sJson:·gc.alloc.rate                 128  thrpt    5    1564.378 ±     8.950  MB/sec
[info] ArrayOfIntsReading.smithy4sJson:·gc.alloc.rate.norm            128  thrpt    5    2840.001 ±     0.001    B/op
[info] ArrayOfIntsReading.smithy4sJson:·gc.count                      128  thrpt    5      11.000              counts
[info] ArrayOfIntsReading.smithy4sJson:·gc.time                       128  thrpt    5      12.000                  ms
[info] ArrayOfLongsReading.smithy4sJson                               128  thrpt    5  442792.864 ±  5628.660   ops/s
[info] ArrayOfLongsReading.smithy4sJson:·gc.alloc.rate                128  thrpt    5    2121.064 ±    26.858  MB/sec
[info] ArrayOfLongsReading.smithy4sJson:·gc.alloc.rate.norm           128  thrpt    5    5024.001 ±     0.001    B/op
[info] ArrayOfLongsReading.smithy4sJson:·gc.count                     128  thrpt    5      14.000              counts
[info] ArrayOfLongsReading.smithy4sJson:·gc.time                      128  thrpt    5       8.000                  ms
[info] ArrayOfShortsReading.smithy4sJson                              128  thrpt    5  620585.000 ± 12549.928   ops/s
[info] ArrayOfShortsReading.smithy4sJson:·gc.alloc.rate               128  thrpt    5    1069.831 ±    21.561  MB/sec
[info] ArrayOfShortsReading.smithy4sJson:·gc.alloc.rate.norm          128  thrpt    5    1808.001 ±     0.001    B/op
[info] ArrayOfShortsReading.smithy4sJson:·gc.count                    128  thrpt    5       7.000              counts
[info] ArrayOfShortsReading.smithy4sJson:·gc.time                     128  thrpt    5      10.000                  ms
[info] ArrayOfUUIDsReading.smithy4sJson                               128  thrpt    5  423901.995 ±  4611.354   ops/s
[info] ArrayOfUUIDsReading.smithy4sJson:·gc.alloc.rate                128  thrpt    5    2172.847 ±    23.533  MB/sec
[info] ArrayOfUUIDsReading.smithy4sJson:·gc.alloc.rate.norm           128  thrpt    5    5376.001 ±     0.001    B/op
[info] ArrayOfUUIDsReading.smithy4sJson:·gc.count                     128  thrpt    5      14.000              counts
[info] ArrayOfUUIDsReading.smithy4sJson:·gc.time                      128  thrpt    5       9.000                  ms
[info] ArraySeqOfBooleansReading.smithy4sJson                         128  thrpt    5  951685.988 ± 14748.118   ops/s
[info] ArraySeqOfBooleansReading.smithy4sJson:·gc.alloc.rate          128  thrpt    5     500.878 ±     7.782  MB/sec
[info] ArraySeqOfBooleansReading.smithy4sJson:·gc.alloc.rate.norm     128  thrpt    5     552.000 ±     0.001    B/op
[info] ArraySeqOfBooleansReading.smithy4sJson:·gc.count               128  thrpt    5       3.000              counts
[info] ArraySeqOfBooleansReading.smithy4sJson:·gc.time                128  thrpt    5       5.000                  ms

@@ -100,6 +106,18 @@ object CollectionTag {
}
}

private[this] def copyOf[A](original: Array[A], newLength: Int): Array[A] = ((original: @unchecked) match {
case x: Array[AnyRef] => java.util.Arrays.copyOf(x, newLength)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL you can pattern match against specialised array types and erasure is not a problem

@Baccata
Copy link
Contributor

Baccata commented Feb 10, 2023

The formatter complains, but otherwise, thank you so much for this Andriy !

@Baccata Baccata merged commit 53de8dc into disneystreaming:series/0.17 Feb 10, 2023
@plokhotnyuk plokhotnyuk deleted the series/0.17 branch February 10, 2023 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants