Hi,
I just noticed a possible optimization opportunity in PersistentBag that should save a few cycles. The idea is to:
* introduce a check for empty inputs * desugar the Stream API in to a vanilla loop
In an isolated benchmark this shows the following improvements for a non empty list:
{code:java}Benchmark Mode Cnt Score Error Units MyBenchmark.testOld thrpt 10 4918160,848 ± 476333,853 ops/s MyBenchmark.testOld:·gc.alloc.rate thrpt 10 3674,990 ± 356,040 MB/sec MyBenchmark.testOld:·gc.alloc.rate.norm thrpt 10 784,000 ± 0,001 B/op MyBenchmark.testOld:·gc.churn.G1_Eden_Space thrpt 10 3691,743 ± 424,599 MB/sec MyBenchmark.testOld:·gc.churn.G1_Eden_Space.norm thrpt 10 787,379 ± 38,252 B/op MyBenchmark.testOld:·gc.churn.G1_Old_Gen thrpt 10 0,008 ± 0,005 MB/sec MyBenchmark.testOld:·gc.churn.G1_Old_Gen.norm thrpt 10 0,002 ± 0,001 B/op MyBenchmark.testOld:·gc.count thrpt 10 132,000 counts MyBenchmark.testOld:·gc.time thrpt 10 132,000 ms
MyBenchmark.testDesugared thrpt 10 7748712,133 ± 678271,480 ops/s MyBenchmark.testDesugared:·gc.alloc.rate thrpt 10 3781,201 ± 331,242 MB/sec MyBenchmark.testDesugared:·gc.alloc.rate.norm thrpt 10 512,000 ± 0,001 B/op MyBenchmark.testDesugared:·gc.churn.G1_Eden_Space thrpt 10 3748,724 ± 388,681 MB/sec MyBenchmark.testDesugared:·gc.churn.G1_Eden_Space.norm thrpt 10 507,465 ± 21,594 B/op MyBenchmark.testDesugared:·gc.churn.G1_Old_Gen thrpt 10 0,006 ± 0,005 MB/sec MyBenchmark.testDesugared:·gc.churn.G1_Old_Gen.norm thrpt 10 0,001 ± 0,001 B/op MyBenchmark.testDesugared:·gc.count thrpt 10 124,000 counts MyBenchmark.testDesugared:·gc.time thrpt 10 126,000 ms{code}
For an empty list the following results are produced (testNew being the one with the additional isEmpty() check):
{code:java}Benchmark Mode Cnt Score Error Units MyBenchmark.testNew thrpt 10 271737559,697 ± 26986324,099 ops/s MyBenchmark.testNew:·gc.alloc.rate thrpt 10 0,001 ± 0,001 MB/sec MyBenchmark.testNew:·gc.alloc.rate.norm thrpt 10 ? 10?? B/op MyBenchmark.testNew:·gc.count thrpt 10 ? 0 counts
MyBenchmark.testOld thrpt 10 16822457,057 ± 923755,443 ops/s MyBenchmark.testOld:·gc.alloc.rate thrpt 10 4361,487 ± 239,553 MB/sec MyBenchmark.testOld:·gc.alloc.rate.norm thrpt 10 272,000 ± 0,001 B/op MyBenchmark.testOld:·gc.churn.G1_Eden_Space thrpt 10 4348,023 ± 243,096 MB/sec MyBenchmark.testOld:·gc.churn.G1_Eden_Space.norm thrpt 10 271,328 ± 15,091 B/op MyBenchmark.testOld:·gc.churn.G1_Old_Gen thrpt 10 0,005 ± 0,005 MB/sec MyBenchmark.testOld:·gc.churn.G1_Old_Gen.norm thrpt 10 ? 10?? B/op MyBenchmark.testOld:·gc.count thrpt 10 133,000 counts MyBenchmark.testOld:·gc.time thrpt 10 136,000 ms
MyBenchmark.testOldDesugared thrpt 10 98931889,728 ± 3022778,400 ops/s MyBenchmark.testOldDesugared:·gc.alloc.rate thrpt 10 4526,090 ± 138,244 MB/sec MyBenchmark.testOldDesugared:·gc.alloc.rate.norm thrpt 10 48,000 ± 0,001 B/op MyBenchmark.testOldDesugared:·gc.churn.G1_Eden_Space thrpt 10 4527,010 ± 229,722 MB/sec MyBenchmark.testOldDesugared:·gc.churn.G1_Eden_Space.norm thrpt 10 48,015 ± 2,202 B/op MyBenchmark.testOldDesugared:·gc.churn.G1_Old_Gen thrpt 10 0,006 ± 0,004 MB/sec MyBenchmark.testOldDesugared:·gc.churn.G1_Old_Gen.norm thrpt 10 ? 10?? B/op MyBenchmark.testOldDesugared:·gc.count thrpt 10 132,000 counts MyBenchmark.testOldDesugared:·gc.time thrpt 10 133,000 ms{code}
PR is attached.
Cheers, Christoph |
|