Netflix/RxJava — pull request #1351 by benjchristensen (2014-06-11 03:54:21+00:00)
Title: Backpressure-3: Merge & ObserveOn (Not Production Ready)

Here is a snapshot of working on backpressure. This is NOT production ready and I'm not all that happy with it right now.

- bad performance
- pivot and parallel operators seem broken (concurrency bugs with `merge` I think)
- bad algorithm in `merge`
- need to replace data structures (lists/queues)
- apparent memory leak in `observeOn` with `Schedulers.computation()` that causes JMH tests to fail on it

```
../gradlew benchmarks '-Pjmh=-f 1 -tu s -bm thrpt -wi 5 -i 5 -r 2 -prof GC rx.usecases.*'
```

Master branch (v0.19):

```
Benchmark (size) Mode Samples Mean Mean error Units
r.u.PerfBaseline.forLoopConsumption 1 thrpt 5 379615485.594 15379754.350 ops/s
r.u.PerfBaseline.forLoopConsumption 1024 thrpt 5 328864.473 18187.666 ops/s
r.u.PerfBaseline.iterableViaForLoopConsumption 1 thrpt 5 253622547.509 27125669.781 ops/s
r.u.PerfBaseline.iterableViaForLoopConsumption 1024 thrpt 5 188193.794 10372.260 ops/s
r.u.PerfBaseline.iterableViaHasNextConsumption 1 thrpt 5 338153673.244 13436554.726 ops/s
r.u.PerfBaseline.iterableViaHasNextConsumption 1024 thrpt 5 299124.445 28327.383 ops/s
r.u.PerfBaseline.observableConsumption 1 thrpt 5 31394747.471 781746.789 ops/s
r.u.PerfBaseline.observableConsumption 1024 thrpt 5 245864.811 6657.154 ops/s
r.u.PerfObserveOn.observeOnComputation 1 thrpt 5 391499.859 18397.563 ops/s
r.u.PerfObserveOn.observeOnComputation 1024 thrpt 5 13328.636 306.077 ops/s
r.u.PerfObserveOn.observeOnImmediate 1 thrpt 5 21230728.918 892820.007 ops/s
r.u.PerfObserveOn.observeOnImmediate 1024 thrpt 5 251638.525 3525.681 ops/s
r.u.PerfObserveOn.observeOnNewThread 1 thrpt 5 21527.805 2739.158 ops/s
r.u.PerfObserveOn.observeOnNewThread 1024 thrpt 5 10020.191 188.225 ops/s
r.u.PerfTransforms.flatMapInt 1 thrpt 5 3564189.441 39217.324 ops/s
r.u.PerfTransforms.flatMapInt 1024 thrpt 5 7093.382 179.934 ops/s
r.u.PerfTransforms.flatMapNestedMapFilterTake 1 thrpt 5 2292314.964 137546.825 ops/s
r.u.PerfTransforms.flatMapNestedMapFilterTake 1024 thrpt 5 17.375 0.430 ops/s
r.u.PerfTransforms.mapIntStringInt 1 thrpt 5 9653977.591 122946.457 ops/s
r.u.PerfTransforms.mapIntStringInt 1024 thrpt 5 19772.989 1649.906 ops/s
r.u.PerfTransforms.mapPassThru 1 thrpt 5 19220291.170 1408394.928 ops/s
r.u.PerfTransforms.mapPassThru 1024 thrpt 5 202820.081 27896.934 ops/s
```

With backpressure changes:

```
Benchmark (size) Mode Samples Mean Mean error Units
r.u.PerfBaseline.forLoopConsumption 1 thrpt 5 357110005.600 40841385.201 ops/s
r.u.PerfBaseline.forLoopConsumption 1024 thrpt 5 323485.335 12560.808 ops/s
r.u.PerfBaseline.iterableViaForLoopConsumption 1 thrpt 5 250763283.151 41052831.579 ops/s
r.u.PerfBaseline.iterableViaForLoopConsumption 1024 thrpt 5 184443.933 17732.768 ops/s
r.u.PerfBaseline.iterableViaHasNextConsumption 1 thrpt 5 328354319.566 20021232.226 ops/s
r.u.PerfBaseline.iterableViaHasNextConsumption 1024 thrpt 5 295521.735 60981.106 ops/s
r.u.PerfBaseline.observableConsumption 1 thrpt 5 9523326.320 1946455.684 ops/s	9.5m vs 31.3m
r.u.PerfBaseline.observableConsumption 1024 thrpt 5 84990.974 4275.619 ops/s
r.u.PerfObserveOn.observeOnComputation 1 thrpt 5 367281.334 88162.113 ops/s	367k vs 391k
r.u.PerfObserveOn.observeOnComputation 1024 thrpt failed (ran out of memory apparently, see below)
r.u.PerfObserveOn.observeOnImmediate 1 thrpt 5 7411354.828 1380680.011 ops/s	7.4m vs 21.2m
r.u.PerfObserveOn.observeOnImmediate 1024 thrpt 5 83914.883 6175.528 ops/s
r.u.PerfObserveOn.observeOnNewThread 1 thrpt 5 21795.495 696.339 ops/s	21.7k vs 21.5k
r.u.PerfObserveOn.observeOnNewThread 1024 thrpt 5 15361.160 1052.314 ops/s	15.3k vs 10k
r.u.PerfTransforms.flatMapInt 1 thrpt 5 1194526.066 91077.184 ops/s	1.2m vs 3.6m
r.u.PerfTransforms.flatMapInt 1024 thrpt 5 1799.220 70.146 ops/s
r.u.PerfTransforms.flatMapNestedMapFilterTake 1 thrpt 5 858432.448 135990.002 ops/s	858k vs 2292k
r.u.PerfTransforms.flatMapNestedMapFilterTake 1024 thrpt 5 45.345 1.928 ops/s	17 vs 45 (something is wrong here on both)
r.u.PerfTransforms.mapIntStringInt 1 thrpt 5 4433584.545 1336597.807 ops/s	4.4m vs 9.6m
r.u.PerfTransforms.mapIntStringInt 1024 thrpt 5 17271.313 881.956 ops/s
r.u.PerfTransforms.mapPassThru 1 thrpt 5 6098106.967 526635.319 ops/s	6.1m vs 19.2m
r.u.PerfTransforms.mapPassThru 1024 thrpt 5 81472.209 5419.922 ops/s

r.u.PerfObserveOn.observeOnComputation with size 1024

Iteration 1: 1052.083 ops/s
GC | wall time = 2.952 secs, GC time = 2.945 secs, GC% = 99.76%, GC count = +3
|

Iteration 2: 161.619 ops/s
GC | wall time = 2.766 secs, GC time = 2.765 secs, GC% = 99.96%, GC count = +3
|
```