Android DTT #9 — Generate Parcelable Boilerplate Automatically
Ahmad Fadli Basyari
252

I really don't know where it is comming from, but I've seen a bunch of articles recommending Parcelable over Serializable, claiming the former is more efficient. But this is just a myth (or comparing apples and oranges). Serializable have option to be used as markup only, where the entire serialization code is going to be generated at runtime using reflection, thus there is performance penalty, but still the performance is amazing, considering the circumstances and ease of use (no boiler plate code to maintain). Then you have option to use Serializable and provide the manual serialization methods. You can also use Externalizable, which is extension to Serializable (using different type of IO streams). If you use this technique, the Serializable is about 2x faster than Parcelable, see this :

Another important aspect is that using Parcels in proposed scenario is basically a misuse of the concept.

See the official Android documentation on Parcel :

Parcel is not a general-purpose serialization mechanism. This class (and the corresponding Parcelable API for placing arbitrary objects into a Parcel) is designed as a high-performance IPC transport.

This explains the reason why Parcelable is slower…it is IPC protocol. Thus unless you do inter process communication there is probably no need to use Parcelables.

To sum it up : You recommend solution that is slower, not really suitable for the task, and doesn't have simple markup option that can be naturally improved in the cases where the performance optimization actually makes sense (based on some profiling information, guess we agree that it is good practice to optimise hotspots, and hotspots only)…doesn't really make sense.