akarnokd / akarnokd/akarnokd-misc

Benchmark 9/19

Ouverte
#2 5 commentaires 26 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Java
Étoiles
54
Forks
20
Merge moyen
1 h 20 min
PR mergées (30 j)
5

Description

# See the most recent comparison in #7.

# Comparative benchmark
- RxJava 1.2 (9/17)
- RxJava 2.0.0-DP0-SNAPSHOT (9/15)
- Reactor Core 3.0.3-BUILD.SNAPSHOT (9/19)

Environment:
- i7 4790 stock settings
- Windows 7 x64
- Java 8u102
- JMH 1.13
- `-XX:MaxInlineLevel=20`

Green is good, red is not so good.
- JMH-Compare-GUI workspace file with the data: https://gist.github.com/akarnokd/6550d42f4a4fb7bbead0ea3afdbbf42e
## Subscribe to a simple source

![image](https://cloud.githubusercontent.com/assets/1269832/18634261/832f5d4a-7e80-11e6-8121-aebe34e89429.png)

Just comparing 1.x and 2.x

![image](https://cloud.githubusercontent.com/assets/1269832/18634280/93a82d0a-7e80-11e6-9485-5496fc98483f.png)

**Remarks**:
- Subscribing to any type in 2.x has lower overhead than 1.x.
## Streaming multiple values (synchronous)

![image](https://cloud.githubusercontent.com/assets/1269832/18634293/9ff06366-7e80-11e6-971e-654843b47e62.png)

**Remarks**:
- There seems to be some extra overhead in the backpressured `concatMapXRange` (both 2.x and Reactor).
- Also `flatMapJust` has extra overhead for all 2.x types (could be unavoidable atomics).
- `flatMapXRange` 1M (which is `flatMapJust` 1M essentially) suffers the same overhead.
- 2.x `Observable.flatten` is not optimized yet and delegates to plain `flatMap`
- Otherwise, nice improvements all over the board.
## Asynchronous and pipelined streaming

![image](https://cloud.githubusercontent.com/assets/1269832/18634315/b482bf5e-7e80-11e6-9087-74ed712efe33.png)

**Remarks**:
- There seems to be some extra overhead or missing optimization from Flowable async 1.
- 2.x Observable lack of optimization (1-case) and likely buffer-bloat in longer streams.
- Generally not bad, but such benchmarks can be hectic (on Windows especially).
## Memory usage

![image](https://cloud.githubusercontent.com/assets/1269832/18634330/c329b92c-7e80-11e6-9d91-ec9e323afb4e.png)

**Remarks**:
- Generally half the memory usage.
- `empty()` seems to be occupying too much memory as if there 1M unique empty() instance.
- `Behavior` and `Unicast` seem to occupy double the memory for some reason.
## Subject/Processor synchronous streaming

![image](https://cloud.githubusercontent.com/assets/1269832/18636016/8da6222a-7e87-11e6-8e53-80a680db4c71.png)

**Remarks**:
- `Async`, `Publish` and small `Replay` is definitely faster in 2.x
- Larger `Replay`, any `Unicast` and any `Behavior` are half-to-quarter slower for some unknown reason.
## Blocking for an item (or completion)

![image](https://cloud.githubusercontent.com/assets/1269832/18634366/e756a422-7e80-11e6-80e9-eaccaf7bbfbe.png)

![image](https://cloud.githubusercontent.com/assets/1269832/18634458/31ad64de-7e81-11e6-903a-cbcb9fd00f3b.png)

![image](https://cloud.githubusercontent.com/assets/1269832/18634462/35a2b0da-7e81-11e6-916f-10ca0c580256.png)

**Remarks**:
- All seem to better at blockingly retrieve one element, except 2.x `Observable` for some reason.
- Reactor is optimized on blocking `empty()` retrieval
# Reactor 3 vs RxJava 2
- They have the same underlying architecture style.
- Operator internals are practically the same for most `Flowable`/`Flux` types.
- **Reactor** delegates some of its `Mono` operators to `Flux` operator internals.
- **Reactor** has more operators fusion-enabled, **RxJava** has most important operators fusion-enabled, its `Observable` has not been extensively optimized though.
- **Reactor** uses queue-suppliers, **RxJava** creates specific queues in operators.
- **Reactor** uses atomic field updaters, **RxJava** extends `AtomicXXX` classes but otherwise uses AtomicXXX instance fields.
- **Reactor** has only an `onAssembly` hook, **RxJava** has a subscribe-time hook and indirection on top of `onAssembly` hook.
## Subscribing

![image](https://cloud.githubusercontent.com/assets/1269832/18635276/c6f6f278-7e84-11e6-8f2c-94ef23a849bb.png)

**Remarks**:
- Reactor uses a weaker form of backpressure in `just` and thus slightly better.
## Streaming synchronously

![image](https://cloud.githubusercontent.com/assets/1269832/18635391/37f762fa-7e85-11e6-9b3f-784b82bff3ed.png)

**Remarks**:
- Most operators are within the +/- 5% error margin.
- Reactor's `flatMap` seems to be slightly faster (5-15%)
- Reactor's `flatten` seems to be reasonably faster (1.5x to 2x).
- Reactor's `iterable` seems to be slightly slower (5-15%)
## Async streaming

![image](https://cloud.githubusercontent.com/assets/1269832/18635586/d66c56ac-7e85-11e6-9be4-0e1038c5c84c.png)

**Remarks**:
- The `async` benchmark is a bit hectic, inconclusive which is better
- Reactor likes longer `pipeline`d streams but dislikes shorter `pipeline`d streams.
## Memory use

![image](https://cloud.githubusercontent.com/assets/1269832/18635689/24bf12fe-7e86-11e6-995c-eab95917e65b.png)

**Remarks**:
- Inconclusive, Reactor has more overhead in places and less in others.
- Reactor's processors are more compacted but leak API.
- Reactor has some drastic `Replay` overhead.
## Processor overhead

![image](https://cloud.githubusercontent.com/assets/1269832/18636095/dafb7f02-7e87-11e6-95ae-44509babf404.png)

**Remarks**:
- Reactor is faster in general but slightly slower in large `Replay` and `Unicast`
## Blocking

![image](https://cloud.githubusercontent.com/assets/1269832/18636182/256ecac6-7e88-11e6-9cf8-8c88a415acd7.png)

**Remarks**:
- Reactor is optimized for blocking on an `empty()`

![image](https://cloud.githubusercontent.com/assets/1269832/18636231/5bbd3a04-7e88-11e6-87da-11b82d97eb3b.png)

**Remarks**:
- Blocking for the first element is the same.

![image](https://cloud.githubusercontent.com/assets/1269832/18636277/7268c25a-7e88-11e6-8ef5-0f2e6642a718.png)

**Remarks**:
- Blocking for the last element is slower in Reactor.
# Conclusion
- RxJava 2.x is generally better in terms of performance and memory utilization than 1.x; most lower performing components can be optimized further.
- Reactor is generally 10-50% better in a Java 8 environment due to more inlined nature and even fewer allocations than RxJava 2.

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.