-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
Closed
Description
I noticed that the Realtime chart demo can stutter due to many repeated and wasteful allocations in sections of code that are called in each update of the data, and it would be great to smooth out the animations and remove stuttering. I've so far identified, verified, and tested ways to reduce the number of allocations by approximately 70% and memory consumed by about 30%, with an attendant improvement in animation quality through various means, such as:
- Eliminating the use of convenience iterations in favor of old fashioned iteration.
for(;;){} instead of
for(Object foo : inSet){} - Caching the results of String Formatting and using those cached results when the value in the dataset has not changed
- Using field level references to store short-lived instances within methods and re-setting them instead of instantiating a new one
eg 1: instead of instantiating a float[] temp = new float[2]; inside a method
declare the float[] as a private field and initialize its two locations as needed.
eg 2: instead of instantiating a new Matrix inside of a function, create a Matrix field and call matrix.reset(); where previously a new Matrix would be instantiated. - Pre-instantiating runnables outside of a local Thread object's run method when each Runnable instance performs the same action on the same object instance
Other means that I have not yet explored but deserve some research include using object pooling for frequently instantiated objects such as FSize, PointF, and the like.
Attached are the results from the memory monitor in Android Studio
Metadata
Metadata
Assignees
Labels
No labels