Netflix/RxJava — pull request #1158 by akarnokd (2014-05-06 08:37:41+00:00)
Title: Scheduler correctness improvements.

Second round on the scheduler correctness issue.

Sure it looks more heavy as ```ScheduledAction``` now has its own inner ```CompositeSubscription``` and a shared reference to the parent ```innerSubscription```.

I've tried to benchmark it with ```SchedulerPerformanceTests``` but that test is flawed:
- Multiple threads pound on the same long sum value, so naturally additions get lost.
- The LongObserver gets unsubscribed after the first loop so ```from``` will not actually call ```onNext``` but ```isUnsubscribed``` a lot.
- Does not wait for the computations to finish and basically measures how fast 5M tasks can be added to the NewThreadScheduler's innerSubscription.

The flawed test gives ~ 11M ops/sec on my machine. If I fix the test and run against the master, 5M takes extremely long to finish due to the inherent slowness of add/remove in CompositeSubscription if large. On my 4 core hyperthread enabled machine, I get 50k-150k ops/second for baseline with a 100k loop.

The proposed changes run with the flawed test gives ~10.8M ops/sec. With the test fixed and with the proposed changes, I get ~1.2M ops/sec.