Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CompositeSubscription memory reduction #818

Merged

Conversation

akarnokd
Copy link
Member

@akarnokd akarnokd commented Feb 5, 2014

Since CompositeSubscription is now used everywhere with Subscriber, I looked at the code again and tried to reduce memory consumption. I've added CLEAR_STATE_UNSUBSCRIBED singleton to transition into when unsubscribed. Note that the previous version kept the subscription array after the unsubscription, keeping references to other subscriptions alive (although unsubscribed); I'm not certain why unsubscription didn't simply discard the array before.

I've played with changing the add and remove methods (not included in this PR) to do more direct array manipulation with about 10-40% speed increase for tests like add directly followed by remove. The speed increase comes from:

  • using arraycopy to avoid dynamic array creation in copyOf,
  • handling case where CS contains a single item to be removed and transitions into CLEAR_STATE instead of creating a new empty state.

Similar memory reduction could be implemented in MAS and SAS.

@cloudbees-pull-request-builder

RxJava-pull-requests #738 SUCCESS
This pull request looks good

@benjchristensen
Copy link
Member

This is great stuff, thank you. I've been considering spending time on this myself so thanks for taking it on. The changes involving arrayCopy sound great as well.

benjchristensen added a commit that referenced this pull request Feb 5, 2014
CompositeSubscription memory reduction
@benjchristensen benjchristensen merged commit e5ab8a9 into ReactiveX:master Feb 5, 2014
@akarnokd akarnokd deleted the CompositeSubscriptionPerf3 branch May 6, 2014 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants