Wednesday, November 8, 2017

Twitter Introduces Serial: an Open Source Library for Serialization

UI smoothness in Android is something that gets brought up from time to time as it can be really easy for the average user to notice what is commonly referred to as jank. This is quite often noticed when scrolling through a list of items and Twitter noticed that serializing and deserializing data both to and from the database using the standard Android Externalizable classes took up about 15% of the UI thread time. The team took some time to optimize this issue and today they’ve announced Serial — a new, open source library for serialization.

Twitter noticed they were running into four main pain points when dealing with the standard Android serialization libraries. This included the performance, the debuggability, the backwards compatibility, and the flexibility. With a view to solve these, the team looked into other Java serialization libraries like Kryo and Flatbuffer; and while these libraries do attempt to solve some of these overlapping problems, they were unable to find any libraries that would fit Twitter’s needs effectively on Android.

So they began working on their own solution and this has resulted in the new open source library for serialization called Serial. As mentioned, the first issue they wanted to solve had to do with performance and Twitter engineers pinpointed reflection as the culprit here. Externalizable allows the framework to identify which object to instantiate with the serialized data, and where to find that class in the app package structure, but it is a time consuming process. To make this more efficient, Serial allows the developer to define a Serializer for each object that needs to be serialized.

Twitter Serial

Debuggability was another issue they wanted to solve and they did this by enabling Serial to provide an exception result with exact unexpected value along with a dump of the structure of the serialized data to allow the developer to see where in the object the issue occurred. They were able to make it backwards compatible so that if a developer wanted to make a change to a model object, then it would not break serialization or require a database clean. To get around this, they added versioning so that developers could make changes quickly and without additional cost.

Lastly, they wanted Serial to be flexible and easy to use so that it wouldn’t require significant changes to the existing model structure. The team was able to do this by defining Serializer as a standalone class that can be statically called to serialize an object. So that almost any model object can be serialized using this framework, including existing Android objects or objects from other imported libraries.

Be sure to read through the full blog post linked below to learn more about the technical details of Serial.


Source: Twitter Blog

HostGator Web Hosting

0 comments:

Post a Comment