User:CFeng (WMF)/PerformanceExperiment

In the Wikipedia Android app, we are mostly using the Gson.marshal to serialize and deserialize objects to pass data between Activity and Fragment.

And in the recently created ticket [|T193275], I’ve tried to use the Serializable on the object for passing data. ([|patch])

Considering the performance issue between the two types of making an object serializable, I did a simple comparison for them.

The code logic is:
 * 1) GalleryActivity.java calls GalleryItemFragment.newIntance and set the RbGalleryItem as an argument to the bundle.
 * 2) When the GalleryItemFragment.OnCreate is created, onCreate will get the RbGalleryItem argument from the bundle.
 * 3) At the beginning of putting RbGalleryItem argument to the bundle, a “start time” will be assigned.
 * 4) At the end of getting the RbGalleryItem argument from the bundle, an “end time” will be assigned.
 * 5) Show the end_time - start_time as the responding time in the Logcat.

The testing logic is:
 * 1) Open the article Barack_Obama in the Wikipedia Android app.
 * 2) Tap on the lead image to enter the GalleryActivity
 * 3) Run n loops for putting and getting RbGalleryItem argument.
 * 4) Try to swipe to the next images.
 * 5) Look at the log of responding time in milliseconds.

The log file [] shows the responding time in different numbers of loops, and we can see the object that uses Gson.marshal will make the app getting slower and slower when the loop numbers increase.

Serializable VS. Gson.marshal 1 loop: 1ms vs. 1.5ms

1,000 loops: 2ms vs. 180ms

10,000 loops: 3ms vs. 1,200ms

100,000 loops: 15ms vs. 10,000ms

1,000,000 loops: 110ms vs N/A

For the huge gap of responding time between the two serializable types, we might start thinking about replacing the Gson.marshal to Serializable to our existing code and for the new features.