uber / RxDogTag

Automatic tagging of RxJava 2+ originating subscribe points for onError() investigation.
https://uber.github.io/RxDogTag
Apache License 2.0
648 stars 19 forks source link

Check performance of guarded delegate calls #20

Closed ZacSweers closed 5 years ago

ZacSweers commented 5 years ago

Requires #17 to be done to add some benchmarking for comparison. If it's expensive, consider putting behind a config

ShaishavGandhi commented 5 years ago

Some preliminary results from putting guarded delegate behind a config.

Event throughput: grouped by number of events:

1 item (observable)
RxDogTagAndroidPerf.observable1_false                                                 302ns    0.000ms
RxDogTagAndroidPerf.observable1_true_withoutGuardedDelegate                        15,980ns    0.016ms  5191.39%
RxDogTagAndroidPerf.observable1_true                                               16,681ns    0.017ms  5423.51%

1 item (flowable)
RxDogTagAndroidPerf.flowable1_false                                                   452ns    0.000ms
RxDogTagAndroidPerf.flowable1_true_withoutGuardedDelegate                          16,214ns    0.016ms  3487.17%
RxDogTagAndroidPerf.flowable1_true                                                 16,821ns    0.017ms  3621.46%

1000 items (observable)
RxDogTagAndroidPerf.observable1000_false                                           27,873ns   0.028ms
RxDogTagAndroidPerf.observable1000_true_withoutGuardedDelegate                     50,833ns   0.051ms  82.37%
RxDogTagAndroidPerf.observable1000_true                                           242,344ns   0.242ms  769.46%

1000 items (flowable)
RxDogTagAndroidPerf.flowable1000_false                                             28,783ns   0.029ms
RxDogTagAndroidPerf.flowable1000_true_withoutGuardedDelegate                       51,597ns   0.052ms  79.26%
RxDogTagAndroidPerf.flowable1000_true                                             207,969ns   0.208ms  622.54%

1000000 items (observable)
RxDogTagAndroidPerf.observable1000000_false                                    27,728,336ns  27.728ms
RxDogTagAndroidPerf.observable1000000_true_withoutGuardedDelegate              36,405,368ns  36.405ms    31.29%
RxDogTagAndroidPerf.observable1000000_true                                    274,318,622ns  274.319ms   889.31%

1000000 items (flowable)
RxDogTagAndroidPerf.flowable1000000_false                                      28,777,451ns  28.777ms
RxDogTagAndroidPerf.flowable1000000_true_withoutGuardedDelegate                36,235,889ns  36.236ms    25.92%
RxDogTagAndroidPerf.flowable1000000_true                                      218,021,428ns  218.021ms   657.61%

Subscribe cost: grouped by complexity:

Simple (observable)
RxDogTagAndroidPerf.observable_false_subscribe_simple                                 220ns    0.000ms
RxDogTagAndroidPerf.observable_true_subscribe_simple_withoutGuardedDelegate        15,845ns    0.016ms  7102.27%
RxDogTagAndroidPerf.observable_true_subscribe_simple                               15,951ns    0.016ms  7150.45%

Simple (flowable)
RxDogTagAndroidPerf.flowable_false_subscribe_simple                                   201ns    0.000ms
RxDogTagAndroidPerf.flowable_true_subscribe_simple                                 15,928ns    0.016ms  7824.38%
RxDogTagAndroidPerf.flowable_true_subscribe_simple_withoutGuardedDelegate          15,935ns    0.016ms  7827.86%

Complex (observable)
RxDogTagAndroidPerf.observable_false_subscribe_complex                              2,843ns   0.003ms
RxDogTagAndroidPerf.observable_true_subscribe_complex                              22,103ns   0.022ms  677.45%
RxDogTagAndroidPerf.observable_true_subscribe_complex_withoutGuardedDelegate       25,474ns   0.025ms  796.03%

Complex (flowable)
RxDogTagAndroidPerf.flowable_true_subscribe_complex                                29,057ns   0.029ms
RxDogTagAndroidPerf.flowable_true_subscribe_complex_withoutGuardedCall             37,796ns   0.038ms  30.08%
RxDogTagAndroidPerf.flowable_false_subscribe_complex                               70,442ns   0.070ms  142.43%

E2E amortized cost:

Observable
RxDogTagAndroidPerf.observable_false_e2e                                           91,770ns  0.092ms
RxDogTagAndroidPerf.observable_true_e2e_withoutGuardedDelegate                    121,980ns  0.122ms  32.92%
RxDogTagAndroidPerf.observable_true_e2e                                           141,563ns  0.142ms  54.26%

Flowable
RxDogTagAndroidPerf.flowable_false_e2e                                            115,781ns  0.116ms
RxDogTagAndroidPerf.flowable_true_e2e                                             166,822ns  0.167ms  44.08%
RxDogTagAndroidPerf.flowable_true_e2e_withoutGuardedDelegate                      173,802ns  0.174ms  50.11%
ZacSweers commented 5 years ago

Wowsers, so the guarded delegate calls seem to be most of the cost. This matches what I saw in some preliminary testing. We should definitely add a flag to control them in Configuration

ZacSweers commented 5 years ago

CC @dlew