On Fri, 12 Apr 2024 16:49:49 GMT, Anthony Scarpino <ascarp...@openjdk.org> wrote:
>> Increase buffer size in CipherInputStream from 512 bytes to 8192 bytes. >> >> I have seen applications where this small buffer size significantly reduces >> throughput, and I've even seen applications which use reflection to modify >> the buffer size to work around the issue. >> >> Using the existing `AESGCMCipherInputStream` benchmark, we can see that 8192 >> performs better in all the explored cases than 512. Sometimes other sizes >> beat 8192, but it seems a good compromise of performance across >> encrypt/decrypt and memory usage, plus it's in line with other JDK classes >> like ChannelInputStream and FileInputStream. >> >> ### Benchmark results >> >> >> make test >> TEST=micro:org.openjdk.bench.javax.crypto.full.AESGCMCipherInputStream >> >> >> 8192 wins substantially for encrypt of both data sizes, and wins noticeably >> for small decrypt data size, while remaining roughly equal for large decrypt >> data size (why are the error bars so wide there...?) >> >> >> (benchmark) (dataSize) Score Error Units >> == buffer size = 512 (current) == >> decrypt 16384 41800.053 +- 674.761 ops/s >> decrypt 1048576 219.218 +- 4509.696 ops/s >> encrypt 16384 59481.957 +- 2297.546 ops/s >> encrypt 1048576 1030.822 +- 48.273 ops/s >> >> == buffer size = 8192 (this PR) == >> decrypt 16384 45023.512 +- 351.284 ops/s >> decrypt 1048576 217.506 +- 4498.711 ops/s >> encrypt 16384 71678.424 +- 1731.105 ops/s >> encrypt 1048576 1562.457 +- 50.944 ops/s >> >> == other candidates (rejected) == >> buffer size = 128 >> decrypt 16384 36282.200 +- 3827.690 ops/s >> decrypt 1048576 200.096 +- 3972.338 ops/s >> encrypt 16384 38352.717 +- 5030.671 ops/s >> encrypt 1048576 671.195 +- 84.134 ops/s >> buffer size = 2048 >> decrypt 16384 44411.579 +- 2452.429 ops/s >> decrypt 1048576 224.036 +- 4582.988 ops/s >> encrypt 16384 65907.313 +- 2678.562 ops/s >> encrypt 1048576 1232.242 +- 53.233 ops/s >> buffer size = 32768 >> decrypt 16384 51004.362 +- 3147.855 ops/s >> decrypt 1048576 205.818 +- 4233.473 ops/s >> encrypt 16384 58716.428 +- 269.514 ops/s >> encrypt 1048576 1564.075 +- 43.732 ops/s >> buffer size = 131702 >> decrypt 16384 32111.911 +- 766.159 ops/s >> decrypt 1048576 247.852 +- 5533.972... > > Can you provide memory usage difference between the current and your > suggested change with `-prof gc`? With many of these situations, it's a > balance between memory usage and performance. @ascarpino here's the `-prof gc` results. Allocations per operation are very similar except for encryption for the smaller data size which is significantly increased with the higher buffer size. I think it's a good tradeoff. Benchmark (dataSize) Score Error Units == buffer size = 512 (current) == decrypt 16384 42899.496 +- 3404.480 ops/s decrypt:gc.alloc.rate 16384 4774.449 +- 378.949 MB/sec decrypt:gc.alloc.rate.norm 16384 116712.005 +- 0.001 B/op decrypt:gc.count 16384 30.000 counts decrypt:gc.time 16384 26.000 ms decrypt 1048576 216.439 +- 4456.148 ops/s decrypt:gc.alloc.rate 1048576 1309.082 +- 26952.072 MB/sec decrypt:gc.alloc.rate.norm 1048576 6342754.317 +- 28.317 B/op decrypt:gc.count 1048576 14.000 counts decrypt:gc.time 1048576 15.000 ms encrypt 16384 58705.848 +- 4776.928 ops/s encrypt:gc.alloc.rate 16384 1991.982 +- 162.581 MB/sec encrypt:gc.alloc.rate.norm 16384 35584.003 +- 0.001 B/op encrypt:gc.count 16384 20.000 counts encrypt:gc.time 16384 18.000 ms encrypt 1048576 1043.335 +- 3.965 ops/s encrypt:gc.alloc.rate 1048576 1062.342 +- 4.239 MB/sec encrypt:gc.alloc.rate.norm 1048576 1067786.612 +- 329.146 B/op encrypt:gc.count 1048576 13.000 counts encrypt:gc.time 1048576 12.000 ms == buffer size = 8192 (this PR) == decrypt 16384 45684.692 +- 2727.992 ops/s decrypt:gc.alloc.rate 16384 5061.666 +- 301.766 MB/sec decrypt:gc.alloc.rate.norm 16384 116192.004 +- 0.001 B/op decrypt:gc.count 16384 31.000 counts decrypt:gc.time 16384 26.000 ms decrypt 1048576 225.570 +- 4656.137 ops/s decrypt:gc.alloc.rate 1048576 1357.667 +- 28024.557 MB/sec decrypt:gc.alloc.rate.norm 1048576 6311970.495 +- 23.307 B/op decrypt:gc.count 1048576 14.000 counts decrypt:gc.time 1048576 15.000 ms encrypt 16384 72738.244 +- 6063.511 ops/s encrypt:gc.alloc.rate 16384 4066.224 +- 338.790 MB/sec encrypt:gc.alloc.rate.norm 16384 58624.003 +- 0.001 B/op encrypt:gc.count 16384 34.000 counts encrypt:gc.time 16384 27.000 ms encrypt 1048576 1552.973 +- 34.944 ops/s encrypt:gc.alloc.rate 1048576 1615.335 +- 36.420 MB/sec encrypt:gc.alloc.rate.norm 1048576 1090816.131 +- 0.003 B/op encrypt:gc.count 1048576 19.000 counts encrypt:gc.time 1048576 16.000 ms ------------- PR Comment: https://git.openjdk.org/jdk/pull/18763#issuecomment-2056362499