Skip to content
New issue

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

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

Already on GitHub? # to your account

RxJava ObjectPool creates unneccessary recurring timer which consumes battery on Android #4845

Closed
borland opened this issue Nov 13, 2016 · 3 comments
Labels
Milestone

Comments

@borland
Copy link

borland commented Nov 13, 2016

We have an Android app which uses RxJava and has a Background Service; The background service process uses RxJava also.

Some of our users report an impact on battery life during idle periods (e.g. overnight) even though our background service has no work to do.

I did some profiling, and discovered RxJava creates two instances of the ObjectPool class, for pooling instances of SpscArrayQueue and SpmcArrayQueue. These appear to be used indirectly by the Merge and Zip observable operators.

The ObjectPool class internally creates a recurring timer which runs every 67 seconds persistently. This timer runs regardless of whether there is any work to do, and it shows up under profiling. We believe this may be the cause of battery life drain overnight, as every 67 seconds the phone must wake up.

Refer to line 113 of ObjectPool.java

f = w.scheduleAtFixedRate(new Runnable() {

It would seem more prudent to only start this timer when the pool is accessed, and stop the timer if the pool is not being used.

I hope to have a pull request ready in a few days

@akarnokd
Copy link
Member

It's time to remove that class.

Note however, that there are other periodic timers such as io() scheduler cleanup (every minute) and thread-pool purging on a Java 6 runtime (every second).

I'm preparing a PR that removes ObjectPool and add documentation to Schedulers about which system parameter to change for the latter two.

@akarnokd akarnokd added the 1.x label Nov 13, 2016
@akarnokd akarnokd added this to the 1.3 milestone Nov 13, 2016
@akarnokd
Copy link
Member

See #4846

@akarnokd
Copy link
Member

Closing via #4846

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants