0

Currently, I am having around 100 Pojo's which implements serializable and passed throughout the app, Since I am expecting more to come as the app grows & it will be better to make use of parcelable.

Will there be any significant performance gain and how can I measure it?

I know about android studio profiler etc. but not really aware which area I will see the performance gain i.e overall app speed, memory consumption etc.

Also, any thing to take care of while making this change?

farhan patel
  • 1,490
  • 2
  • 19
  • 30

1 Answers1

0

According to Philippe Breault's benchmark, Parcelable is way faster than Serializable. He tested it on 3 different devices, with Android versions 2.3.3 and 4.2.2.

You can see the results below.

benchmark

  • Nexus 10 Serializable: 1.0004ms – Parcelable: 0.0850ms - 10.16x faster.

  • Nexus 4 Serializable: 1.8539ms – Parcelable: 0.1824ms - 11.80x faster.

  • Desire Z Serializable: 5.1224ms – Parcelable: 0.2938ms - 17.36x faster.

Those numbers are for a single object, passed through a Bundle 1000 times around. If you're expecting to add 100+ more, things will escalate quickly.

Serializable is a standard Java interface, and it tends to leave a lot of temporary objects behing, which can trigger many GC events.

Parcelable on the other hand, is an Android interface, that was conceived to tackle performance issues, and it achieves that by not using reflection on the serialization. Thing is, you have to define the serialization yourself. But you'll get a huge performance difference compared to Serializable objects.

You can read more about Parcelable on the docs.

Also, related answer on why you should use Parcelable.

Mauker
  • 11,237
  • 7
  • 58
  • 76