Netflix/RxJava — pull request #652 by akarnokd (2013-12-22 14:00:52+00:00)
Title: Subjects fixes

Improvements upon Ben's excellent work:

- (Original performance for me was 1.662.152 ops/sec on average.)
- Storing subscriptions and observers in arrays rather than in a Map inside ```SubjectSubscriptionManager.```. This adds +2.340.000 ops/sec on average; total ~ 4.000.000 ops/sec so far.
- ```SafeObserver``` uses a volatile for the actual Observer which is swapped to a ```nopObserver``` if a terminal case occurs. This avoids an atomic get and if statement and adds a +100.000 ops/second on average; total ~4.100.000 ops/sec so far.
- I suggest adding a create option to set the initial buffer size (not done here) which would reduce the number of array-resizes. With 2024 as a sweet spot on my machine, this adds +1.100.000 ops/second; total 5.200.000 so far.

**Bounded version**
We have a boundable ReplaySubject in main named ```CustomReplaySubject``` and PR #649 to improve a bit upon its performance. It might benefit from the changes above as well. It would be a more tricky implementation in terms of the replay operation, since the buffer would be in constant virtual index motion (including its start and end), so observers would need to atomically get a value from it whose index could get below the virtual start index of the buffer. Will think about this.