SlideShare a Scribd company logo
1 of 70
Download to read offline
Don’t Get Lost in Translation
for Serializing Data Structures
Christopher Brown
Principal Mobile Developer – Team Lead, priceline.com
DroidCon NYC
August 28th, 2015
{	
  
	
  	
  	
  	
  “trips”:	
  [	
  
	
  “offerDetails”:	
  {...},	
  
	
  “customer”:	
  {...},	
  
	
  “requestId”:	
  “...”,	
  
	
  ...	
  
	
  	
  	
  	
  ]	
  
}	
  
10
trips
Light Booker
{	
  
	
  	
  	
  	
  “trips”:	
  [	
  
	
  “offerDetails”:	
  {...},	
  
	
  “customer”:	
  {...},	
  
	
  “requestId”:	
  “...”,	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
...	
  
	
  	
  	
  	
  ]	
  
}	
  
100
trips
More Frequent Booker
{	
  
	
  	
  	
  	
  “trips”:	
  [	
  
	
  “offerDetails”:	
  {...},	
  
	
  “customer”:	
  {...},	
  
	
  “requestId”:	
  “...”,	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
...	
  
	
  ...	
  
...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
...	
  
	
  ...	
  
	
  ...	
  
	
  	
  	
  	
  ]	
  
}	
  
500
trips
Heavy Booker
JSONObject
new	
  JSONObject(	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  );	
  
{	
  
	
  	
  	
  	
  “trips”:	
  [	
  
	
  “offerDetails”:	
  {...},	
  
	
  “customer”:	
  {...},	
  
	
  “requestId”:	
  “...”,	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
...	
  
	
  ...	
  
...	
  
	
  	
  	
  	
  ]	
  
}	
  
	
  
new	
  JSONObject(	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  );	
  
	
  
{	
  
	
  	
  	
  	
  “trips”:	
  [	
  
	
  “offerDetails”:	
  {...},	
  
	
  “customer”:	
  {...},	
  
	
  “requestId”:	
  “...”,	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
...	
  
	
  ...	
  
...	
  
	
  	
  	
  	
  ]	
  
}	
  
	
  
new	
  JSONObject(	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  );	
  
	
  
{	
  
	
  	
  	
  	
  “trips”:	
  [	
  
	
  “offerDetails”:	
  {...},	
  
	
  “customer”:	
  {...},	
  
	
  “requestId”:	
  “...”,	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
	
  ...	
  
...	
  
	
  ...	
  
...	
  
	
  	
  	
  	
  ]	
  
}	
  
	
  
How can we improve the
performance?
Let’s experiment with different
serialization libraries...
Gson
Gson
Provides simple toJson() and fromJson() methods
Gson
Provides simple toJson() and fromJson() methods
Provides streaming access
Gson
Provides simple toJson() and fromJson() methods
Provides streaming access
Operates as sequence of tokens traversed in depth-first order
Gson
Provides simple toJson() and fromJson() methods
Provides streaming access
Operates as sequence of tokens traversed in depth-first order
Minimal memory overhead
Implementation example
public	
  List<Trip>	
  getListOfTrips(	
  InputStream	
  inputStream	
  )	
  throws	
  IOException	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  Gson	
  gson	
  =	
  new	
  Gson();	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  JsonReader	
  reader	
  =	
  new	
  JsonReader(	
  new	
  InputStreamReader(	
  inputStream	
  )	
  );	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  List<Trip>	
  trips	
  =	
  new	
  ArrayList<>();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.beginArray();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  while	
  (	
  reader.hasNext()	
  )	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Trip	
  trip	
  =	
  gson.fromJson(	
  reader,	
  Trip.class	
  );	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  trips.add(	
  trip	
  );	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.endArray();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.close();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  trips;	
  
}	
  
	
  
Implementation example
public	
  List<Trip>	
  getListOfTrips(	
  InputStream	
  inputStream	
  )	
  throws	
  IOException	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  Gson	
  gson	
  =	
  new	
  Gson();	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  JsonReader	
  reader	
  =	
  new	
  JsonReader(	
  new	
  InputStreamReader(	
  inputStream	
  )	
  );	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  List<Trip>	
  trips	
  =	
  new	
  ArrayList<>();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.beginArray();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  while	
  (	
  reader.hasNext()	
  )	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Trip	
  trip	
  =	
  gson.fromJson(	
  reader,	
  Trip.class	
  );	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  trips.add(	
  trip	
  );	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.endArray();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.close();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  trips;	
  
}	
  
	
  
	
  
Implementation example
public	
  List<Trip>	
  getListOfTrips(	
  InputStream	
  inputStream	
  )	
  throws	
  IOException	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  Gson	
  gson	
  =	
  new	
  Gson();	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  JsonReader	
  reader	
  =	
  new	
  JsonReader(	
  new	
  InputStreamReader(	
  inputStream	
  )	
  );	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  List<Trip>	
  trips	
  =	
  new	
  ArrayList<>();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.beginArray();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  while	
  (	
  reader.hasNext()	
  )	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Trip	
  trip	
  =	
  gson.fromJson(	
  reader,	
  Trip.class	
  );	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  trips.add(	
  trip	
  );	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.endArray();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.close();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  trips;	
  
}	
  
	
  
	
  
Implementation example
public	
  List<Trip>	
  getListOfTrips(	
  InputStream	
  inputStream	
  )	
  throws	
  IOException	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  Gson	
  gson	
  =	
  new	
  Gson();	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  JsonReader	
  reader	
  =	
  new	
  JsonReader(	
  new	
  InputStreamReader(	
  inputStream	
  )	
  );	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  List<Trip>	
  trips	
  =	
  new	
  ArrayList<>();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.beginArray();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  while	
  (	
  reader.hasNext()	
  )	
  {	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  Trip	
  trip	
  =	
  gson.fromJson(	
  reader,	
  Trip.class	
  );	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  trips.add(	
  trip	
  );	
  
	
  	
  	
  	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.endArray();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  reader.close();	
  
	
  
	
  	
  	
  	
  	
  	
  	
  	
  return	
  trips;	
  
}	
  
	
  
	
  
Gson performance
87.3 ms 56 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
10 Trips
100 Trips
500 Trips
Gson performance
87.3 ms 56 KB
142.9 ms 399 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
10 Trips
100 Trips
500 Trips
Gson performance
10 Trips
100 Trips
500 Trips
87.3 ms 56 KB
142.9 ms 399 KB
459.2 ms 599 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
Jackson
Jackson
Offers 3 alternative methods for processing JSON (Streaming API, Tree Model,
Data Binding)
Default Jackson only handles strictly valid JSON but can be configured
Provides simple readValue() and readTree() methods
ObjectMapper caching
	
  
Jackson implementation example
public	
  Trips	
  getTrips(	
  String	
  json	
  )	
  {	
  
	
  	
  	
  	
  ObjectMapper	
  objectMapper	
  =	
  new	
  ObjectMapper();	
  
	
  
	
  	
  	
  	
  return	
  objectMapper.readValue(	
  json,	
  Trips.class	
  );	
  
}	
  
	
  
Jackson performance
351 ms 146 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
10 Trips
100 Trips
500 Trips
Jackson performance
351 ms 146 KB
455 ms 386 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
10 Trips
100 Trips
500 Trips
Jackson performance
10 Trips
100 Trips
500 Trips
351 ms 146 KB
636 ms 837 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
455 ms 386 KB
Protocol Buffers
Protocol Buffers
Language and platform neutral mechanism for serializing structured data
Protocol Buffers
Language and platform neutral mechanism for serializing structured data
You specify how you want the information you’re serializing to be structured by
defining protocol buffer message types in .proto files
Protocol Buffers
Language and platform neutral mechanism for serializing structured data
You specify how you want the information you’re serializing to be structured by
defining protocol buffer message types in .proto files
Each protocol buffer message is a logical record of information containing name-
value pairs
Protocol Buffers
Language and platform neutral mechanism for serializing structured data
You specify how you want the information you’re serializing to be structured by
defining protocol buffer message types in .proto files
Each protocol buffer message is a logical record of information containing name-
value pairs
.proto files are used to generate special source code which allows you to
populate, serialize, and parse protocol buffer objects
Protocol Buffers
Language and platform neutral mechanism for serializing structured data
You specify how you want the information you’re serializing to be structured by
defining protocol buffer message types in .proto files
Each protocol buffer message is a logical record of information containing name-
value pairs
.proto files are used to generate special source code which allows you to
populate, serialize, and parse protocol buffer objects
Protocol buffer messages are serialized into a tiny binary format. Serializing and
parsing protocol buffer messages is much faster than JSON.
Protocol Buffers .proto file
package	
  TripsList;	
  
	
  
option	
  java_package	
  =	
  "com.priceline.droidcon.model.proto";	
  
option	
  java_outer_classname	
  =	
  "TripsProtos";	
  
	
  
message	
  Trips	
  {	
  
	
  ...	
  
}	
  
message	
  Trip	
  {	
  
	
  ...	
  
}	
  
message	
  OfferDetails	
  {	
  
	
  ...	
  
}	
  
message	
  PrimaryOffer	
  {	
  
	
  ...	
  
}	
  
message	
  Customer	
  {	
  
	
  ...	
  
}	
  
Protocol Buffers .proto file
package	
  TripsList;	
  
	
  
option	
  java_package	
  =	
  "com.priceline.droidcon.model.proto";	
  
option	
  java_outer_classname	
  =	
  "TripsProtos";	
  
	
  
message	
  Trips	
  {	
  
	
  ...	
  
}	
  
message	
  Trip	
  {	
  
	
  ...	
  
}	
  
message	
  OfferDetails	
  {	
  
	
  ...	
  
}	
  
message	
  PrimaryOffer	
  {	
  
	
  ...	
  
}	
  
message	
  Customer	
  {	
  
	
  ...	
  
}	
  
Protocol Buffers .proto file
package	
  TripsList;	
  
	
  
option	
  java_package	
  =	
  "com.priceline.droidcon.model.proto";	
  
option	
  java_outer_classname	
  =	
  "TripsProtos";	
  
	
  
message	
  Trips	
  {	
  
	
  ...	
  
}	
  
message	
  Trip	
  {	
  
	
  ...	
  
}	
  
message	
  OfferDetails	
  {	
  
	
  ...	
  
}	
  
message	
  PrimaryOffer	
  {	
  
	
  ...	
  
}	
  
message	
  Customer	
  {	
  
	
  ...	
  
}	
  
Protocol Buffers .proto file
package	
  TripsList;	
  
	
  
option	
  java_package	
  =	
  "com.priceline.droidcon.model.proto";	
  
option	
  java_outer_classname	
  =	
  "TripsProtos";	
  
	
  
message	
  Trips	
  {	
  
	
  ...	
  
}	
  
message	
  Trip	
  {	
  
	
  ...	
  
}	
  
message	
  OfferDetails	
  {	
  
	
  ...	
  
}	
  
message	
  PrimaryOffer	
  {	
  
	
  ...	
  
}	
  
message	
  Customer	
  {	
  
	
  ...	
  
}	
  
Protocol Buffers implementation example
public	
  List<Trip>	
  getListOfTrips(	
  byte[]	
  data	
  )	
  {	
  
Trips	
  trips	
  =	
  Trips.parseFrom(	
  data	
  );	
  
	
  
	
  	
  	
  	
  	
  return	
  trips.getTripList();	
  
}	
  
	
  
Protocol Buffers implementation example
public	
  List<Trip>	
  getListOfTrips(	
  byte[]	
  data	
  )	
  {	
  
Trips	
  trips	
  =	
  Trips.parseFrom(	
  data	
  );	
  
	
  
	
  	
  	
  	
  	
  return	
  trips.getTripList();	
  
}	
  
	
  
Protocol Buffers implementation example
public	
  List<Trip>	
  getListOfTrips(	
  byte[]	
  data	
  )	
  {	
  
Trips	
  trips	
  =	
  Trips.parseFrom(	
  data	
  );	
  
	
  
	
  	
  	
  	
  	
  return	
  trips.getTripList();	
  
}	
  
	
  
Protocol Buffers performance
3.816 ms 264 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
10 Trips
100 Trips
500 Trips
Protocol Buffers performance
3.816 ms 264 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
24.231 ms 352 KB
10 Trips
100 Trips
500 Trips
Protocol Buffers performance
10 Trips
100 Trips
500 Trips
3.816 ms 264 KB
24.231 ms 352 KB
102.355 ms 1,728 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
...but, there’s something
faster!
FlatBuffers
FlatBuffers
Efficient open-source, cross platform serialization library
Efficient open-source, cross platform serialization library
Similar to Protocol Buffers but allows you to access information without parsing
the data which results in much better memory performance
FlatBuffers
FlatBuffers
Efficient open-source, cross platform serialization library
Similar to Protocol Buffers but allows you to access information without parsing
the data which results in much better memory performance
A schema let’s you define how you want to structure your data
FlatBuffers
Efficient open-source, cross platform serialization library
Similar to Protocol Buffers but allows you to access information without parsing
the data which results in much better memory performance
A schema let’s you define how you want to structure your data
FlatBuffer is a binary buffer containing data organized by offsets
FlatBuffers
Efficient open-source, cross platform serialization library
Similar to Protocol Buffers but allows you to access information without parsing
the data which results in much better memory performance
A schema let’s you define how you want to structure your data
FlatBuffer is a binary buffer containing data organized by offsets
Faster than JSON and smaller memory footprint than Protocol Buffers
FlatBuffers schema
namespace	
  TripsList;	
  
	
  
table	
  Trips	
  {	
  
	
  trips	
  :	
  [Trip];	
  
}	
  
	
  
table	
  Trip	
  {	
  
	
  ...	
  
}	
  
	
  
table	
  OfferDetails	
  {	
  
	
  ...	
  
}	
  
	
  
...	
  
	
  
root_type	
  Trips;	
  
	
  
	
  
FlatBuffers schema
namespace	
  TripsList;	
  
	
  
table	
  Trips	
  {	
  
	
  trips	
  :	
  [Trip];	
  
}	
  
	
  
table	
  Trip	
  {	
  
	
  ...	
  
}	
  
	
  
table	
  OfferDetails	
  {	
  
	
  ...	
  
}	
  
	
  
...	
  
	
  
root_type	
  Trips;	
  
	
  
	
  
FlatBuffers schema
namespace	
  TripsList;	
  
	
  
table	
  Trips	
  {	
  
	
  trips	
  :	
  [Trip];	
  
}	
  
	
  
table	
  Trip	
  {	
  
	
  ...	
  
}	
  
	
  
table	
  OfferDetails	
  {	
  
	
  ...	
  
}	
  
	
  
...	
  
	
  
root_type	
  Trips;	
  
	
  
	
  
FlatBuffers schema
namespace	
  TripsList;	
  
	
  
table	
  Trips	
  {	
  
	
  trips	
  :	
  [Trip];	
  
}	
  
	
  
table	
  Trip	
  {	
  
	
  ...	
  
}	
  
	
  
table	
  OfferDetails	
  {	
  
	
  ...	
  
}	
  
	
  
...	
  
	
  
root_type	
  Trips;	
  
	
  
	
  
FlatBuffers implementation example
public	
  List<Trip>	
  getListOfTrips(	
  byte[]	
  data	
  )	
  {	
  
Trips	
  trips	
  =	
  Trips.getRootAsTrips(	
  ByteBuffer.wrap(	
  data	
  )	
  );	
  
	
  
	
  	
  	
  	
  List<Trip>	
  list	
  =	
  new	
  ArrayList<>();	
  
	
  
	
  	
  	
  	
  	
  for	
  (	
  int	
  i	
  =	
  0;	
  i	
  <	
  trips.tripsLength();	
  i++	
  )	
  {	
  
	
  	
  	
  	
  	
   	
  list.add(	
  trips.trips(	
  i	
  )	
  );	
  
	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
   	
  return	
  list;	
  
}	
  
	
  
	
  
FlatBuffers implementation example
public	
  List<Trip>	
  getListOfTrips(	
  byte[]	
  data	
  )	
  {	
  
Trips	
  trips	
  =	
  Trips.getRootAsTrips(	
  ByteBuffer.wrap(	
  data	
  )	
  );	
  
	
  
	
  	
  	
  	
  List<Trip>	
  list	
  =	
  new	
  ArrayList<>();	
  
	
  
	
  	
  	
  	
  	
  for	
  (	
  int	
  i	
  =	
  0;	
  i	
  <	
  trips.tripsLength();	
  i++	
  )	
  {	
  
	
  	
  	
  	
  	
   	
  list.add(	
  trips.trips(	
  i	
  )	
  );	
  
	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
   	
  return	
  list;	
  
}	
  
	
  
	
  
FlatBuffers implementation example
public	
  List<Trip>	
  getListOfTrips(	
  byte[]	
  data	
  )	
  {	
  
Trips	
  trips	
  =	
  Trips.getRootAsTrips(	
  ByteBuffer.wrap(	
  data	
  )	
  );	
  
	
  
	
  	
  	
  	
  List<Trip>	
  list	
  =	
  new	
  ArrayList<>();	
  
	
  
	
  	
  	
  	
  	
  for	
  (	
  int	
  i	
  =	
  0;	
  i	
  <	
  trips.tripsLength();	
  i++	
  )	
  {	
  
	
  	
  	
  	
  	
   	
  list.add(	
  trips.trips(	
  i	
  )	
  );	
  
	
  	
  	
  	
  	
  }	
  
	
  
	
  	
  	
  	
   	
  return	
  list;	
  
}	
  
	
  
	
  
FlatBuffers performance
10 Trips 1.304 ms 3.8 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
100 Trips
500 Trips
FlatBuffers performance
10 Trips 1.304 ms 3.8 KB
6.153 ms 6.944 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
100 Trips
500 Trips
FlatBuffers performance
10 Trips
100 Trips
500 Trips
1.304 ms 3.8 KB
6.153 ms 6.944 KB
13.704 ms 13 KB
Incl. CPU Time
Memory Allocation
Tests were performed on a Motorola Nexus 6 running Android 5.1.1
Protocol Buffers
On average 350% faster than
Protocol Buffers
Overall Time Results
Gson
Jackson
Protocol
Buffers
Flat Buffers
459 ms
14 ms
Note: Time results shown for 500 trips
102 ms
636 ms
Our Selection
FlatBuffers was faster and more efficient, but…
Image credits: The Noun Project – Dalpat Prajapati
Our Selection
FlatBuffers was faster and more efficient, but…
Our final decision was Protocol Buffers
Our Selection
FlatBuffers was faster and more efficient, but…
Our final decision was Protocol Buffers
...it’s not the fastest, but it was the most optimal for us
Our Selection
FlatBuffers was faster and more efficient, but…
Our final decision was Protocol Buffers
...it’s not the fastest, but it was the most optimal for us
FlatBuffers is still a great way to serialize and deserialize data
Wrap Up
Don’t get lost in translation for serializing your data structures
Image credits: The Noun Project – Hello Many
Wrap Up
Don’t get lost in translation for serializing your data structures
Different options available (Gson → Jackson → Protocol Buffers →
FlatBuffers)
Wrap Up
Don’t get lost in translation for serializing your data structures
Different options available (Gson → Jackson → Protocol Buffers →
FlatBuffers)
FlatBuffers are the best balance of speed and memory efficiency
(FlatBuffers won the battle, it did not win the war)
Image credits: The Noun Project - Rediffusion
Questions?
christopher.brown@priceline.com

More Related Content

What's hot

MongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB
 
Python client api
Python client apiPython client api
Python client apidreampuf
 
Encryption: It's For More Than Just Passwords
Encryption: It's For More Than Just PasswordsEncryption: It's For More Than Just Passwords
Encryption: It's For More Than Just PasswordsJohn Congdon
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMongoDB
 
The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185Mahmoud Samir Fayed
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDBTakahiro Inoue
 
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 LinkMongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 LinkMongoDB
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationMongoDB
 
Sharding with MongoDB -- MongoDC 2012
Sharding with MongoDB -- MongoDC 2012Sharding with MongoDB -- MongoDC 2012
Sharding with MongoDB -- MongoDC 2012Tyler Brock
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)Skillwise Group
 
NDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersNDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersSimon Elliston Ball
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...MongoDB
 
Building Your First Java Application with MongoDB
Building Your First Java Application with MongoDBBuilding Your First Java Application with MongoDB
Building Your First Java Application with MongoDBMongoDB
 

What's hot (20)

MongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your DataMongoDB World 2018: Using Change Streams to Keep Up with Your Data
MongoDB World 2018: Using Change Streams to Keep Up with Your Data
 
quick json parser
quick json parserquick json parser
quick json parser
 
Python client api
Python client apiPython client api
Python client api
 
Latinoware
LatinowareLatinoware
Latinoware
 
Python and MongoDB
Python and MongoDBPython and MongoDB
Python and MongoDB
 
Encryption: It's For More Than Just Passwords
Encryption: It's For More Than Just PasswordsEncryption: It's For More Than Just Passwords
Encryption: It's For More Than Just Passwords
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
Mongo db for C# Developers
Mongo db for C# DevelopersMongo db for C# Developers
Mongo db for C# Developers
 
The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185The Ring programming language version 1.5.4 book - Part 40 of 185
The Ring programming language version 1.5.4 book - Part 40 of 185
 
はじめてのMongoDB
はじめてのMongoDBはじめてのMongoDB
はじめてのMongoDB
 
Indexing
IndexingIndexing
Indexing
 
Mobile Web 5.0
Mobile Web 5.0Mobile Web 5.0
Mobile Web 5.0
 
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 LinkMongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
MongoDB World 2019: Using Client Side Encryption in MongoDB 4.2 Link
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
New text document
New text documentNew text document
New text document
 
Sharding with MongoDB -- MongoDC 2012
Sharding with MongoDB -- MongoDC 2012Sharding with MongoDB -- MongoDC 2012
Sharding with MongoDB -- MongoDC 2012
 
JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)JSON-(JavaScript Object Notation)
JSON-(JavaScript Object Notation)
 
NDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developersNDC London 2013 - Mongo db for c# developers
NDC London 2013 - Mongo db for c# developers
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
 
Building Your First Java Application with MongoDB
Building Your First Java Application with MongoDBBuilding Your First Java Application with MongoDB
Building Your First Java Application with MongoDB
 

Similar to Don’t Get Lost in Translation for Serializing Data Structures

Functionality Focused Code Organization
Functionality Focused Code OrganizationFunctionality Focused Code Organization
Functionality Focused Code OrganizationRebecca Murphey
 
GraphQL Los Angeles Meetup Slides
GraphQL Los Angeles Meetup SlidesGraphQL Los Angeles Meetup Slides
GraphQL Los Angeles Meetup SlidesGrant Miller
 
[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)croquiscom
 
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsNeo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsMark Needham
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs偉格 高
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsNeo4j
 
Object oriented programming in go
Object oriented programming in goObject oriented programming in go
Object oriented programming in goJaehue Jang
 
GraphTour - Utilizing Powerful Extensions for Analytics & Operations
GraphTour - Utilizing Powerful Extensions for Analytics & OperationsGraphTour - Utilizing Powerful Extensions for Analytics & Operations
GraphTour - Utilizing Powerful Extensions for Analytics & OperationsNeo4j
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsNeo4j
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Andrii Lashchenko
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETTomas Jansson
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.Mike Fogus
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用LearningTech
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeVMware Tanzu
 
Next-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNext-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNikolas Burk
 
Read, store and create xml and json
Read, store and create xml and jsonRead, store and create xml and json
Read, store and create xml and jsonKim Berg Hansen
 
Typescript - why it's awesome
Typescript - why it's awesomeTypescript - why it's awesome
Typescript - why it's awesomePiotr Miazga
 
Modern Networking with Swish
Modern Networking with SwishModern Networking with Swish
Modern Networking with Swishjakecraige
 

Similar to Don’t Get Lost in Translation for Serializing Data Structures (20)

Php sql-android
Php sql-androidPhp sql-android
Php sql-android
 
Functionality Focused Code Organization
Functionality Focused Code OrganizationFunctionality Focused Code Organization
Functionality Focused Code Organization
 
GraphQL Los Angeles Meetup Slides
GraphQL Los Angeles Meetup SlidesGraphQL Los Angeles Meetup Slides
GraphQL Los Angeles Meetup Slides
 
[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)[2019-07] GraphQL in depth (serverside)
[2019-07] GraphQL in depth (serverside)
 
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsNeo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
 
Functional programming using underscorejs
Functional programming using underscorejsFunctional programming using underscorejs
Functional programming using underscorejs
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
Object oriented programming in go
Object oriented programming in goObject oriented programming in go
Object oriented programming in go
 
GraphTour - Utilizing Powerful Extensions for Analytics & Operations
GraphTour - Utilizing Powerful Extensions for Analytics & OperationsGraphTour - Utilizing Powerful Extensions for Analytics & Operations
GraphTour - Utilizing Powerful Extensions for Analytics & Operations
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.Spray Json and MongoDB Queries: Insights and Simple Tricks.
Spray Json and MongoDB Queries: Insights and Simple Tricks.
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
Code as data as code.
Code as data as code.Code as data as code.
Code as data as code.
 
Peggy elasticsearch應用
Peggy elasticsearch應用Peggy elasticsearch應用
Peggy elasticsearch應用
 
The Past Year in Spring for Apache Geode
The Past Year in Spring for Apache GeodeThe Past Year in Spring for Apache Geode
The Past Year in Spring for Apache Geode
 
Next-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and PrismaNext-generation API Development with GraphQL and Prisma
Next-generation API Development with GraphQL and Prisma
 
Read, store and create xml and json
Read, store and create xml and jsonRead, store and create xml and json
Read, store and create xml and json
 
Typescript - why it's awesome
Typescript - why it's awesomeTypescript - why it's awesome
Typescript - why it's awesome
 
Modern Networking with Swish
Modern Networking with SwishModern Networking with Swish
Modern Networking with Swish
 
Advanced Json
Advanced JsonAdvanced Json
Advanced Json
 

Recently uploaded

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 

Recently uploaded (20)

Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 

Don’t Get Lost in Translation for Serializing Data Structures

  • 1. Don’t Get Lost in Translation for Serializing Data Structures Christopher Brown Principal Mobile Developer – Team Lead, priceline.com DroidCon NYC August 28th, 2015
  • 2.
  • 3. {          “trips”:  [    “offerDetails”:  {...},    “customer”:  {...},    “requestId”:  “...”,    ...          ]   }   10 trips Light Booker
  • 4. {          “trips”:  [    “offerDetails”:  {...},    “customer”:  {...},    “requestId”:  “...”,    ...    ...    ...    ...    ...    ...   ...          ]   }   100 trips More Frequent Booker
  • 5. {          “trips”:  [    “offerDetails”:  {...},    “customer”:  {...},    “requestId”:  “...”,    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...   ...    ...   ...    ...    ...    ...    ...   ...    ...    ...          ]   }   500 trips Heavy Booker
  • 7. new  JSONObject(                                );   {          “trips”:  [    “offerDetails”:  {...},    “customer”:  {...},    “requestId”:  “...”,    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...   ...    ...   ...          ]   }    
  • 8. new  JSONObject(                                );     {          “trips”:  [    “offerDetails”:  {...},    “customer”:  {...},    “requestId”:  “...”,    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...   ...    ...   ...          ]   }    
  • 9. new  JSONObject(                                );     {          “trips”:  [    “offerDetails”:  {...},    “customer”:  {...},    “requestId”:  “...”,    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...    ...   ...    ...   ...          ]   }    
  • 10. How can we improve the performance? Let’s experiment with different serialization libraries...
  • 11. Gson
  • 12. Gson Provides simple toJson() and fromJson() methods
  • 13. Gson Provides simple toJson() and fromJson() methods Provides streaming access
  • 14. Gson Provides simple toJson() and fromJson() methods Provides streaming access Operates as sequence of tokens traversed in depth-first order
  • 15. Gson Provides simple toJson() and fromJson() methods Provides streaming access Operates as sequence of tokens traversed in depth-first order Minimal memory overhead
  • 16. Implementation example public  List<Trip>  getListOfTrips(  InputStream  inputStream  )  throws  IOException  {                  Gson  gson  =  new  Gson();                                    JsonReader  reader  =  new  JsonReader(  new  InputStreamReader(  inputStream  )  );                    List<Trip>  trips  =  new  ArrayList<>();                    reader.beginArray();                    while  (  reader.hasNext()  )  {                          Trip  trip  =  gson.fromJson(  reader,  Trip.class  );                            trips.add(  trip  );                  }                    reader.endArray();                    reader.close();                    return  trips;   }    
  • 17. Implementation example public  List<Trip>  getListOfTrips(  InputStream  inputStream  )  throws  IOException  {                  Gson  gson  =  new  Gson();                                    JsonReader  reader  =  new  JsonReader(  new  InputStreamReader(  inputStream  )  );                    List<Trip>  trips  =  new  ArrayList<>();                    reader.beginArray();                    while  (  reader.hasNext()  )  {                          Trip  trip  =  gson.fromJson(  reader,  Trip.class  );                            trips.add(  trip  );                  }                    reader.endArray();                    reader.close();                    return  trips;   }      
  • 18. Implementation example public  List<Trip>  getListOfTrips(  InputStream  inputStream  )  throws  IOException  {                  Gson  gson  =  new  Gson();                                    JsonReader  reader  =  new  JsonReader(  new  InputStreamReader(  inputStream  )  );                    List<Trip>  trips  =  new  ArrayList<>();                    reader.beginArray();                    while  (  reader.hasNext()  )  {                          Trip  trip  =  gson.fromJson(  reader,  Trip.class  );                            trips.add(  trip  );                  }                    reader.endArray();                    reader.close();                    return  trips;   }      
  • 19. Implementation example public  List<Trip>  getListOfTrips(  InputStream  inputStream  )  throws  IOException  {                  Gson  gson  =  new  Gson();                                    JsonReader  reader  =  new  JsonReader(  new  InputStreamReader(  inputStream  )  );                    List<Trip>  trips  =  new  ArrayList<>();                    reader.beginArray();                    while  (  reader.hasNext()  )  {                          Trip  trip  =  gson.fromJson(  reader,  Trip.class  );                            trips.add(  trip  );                  }                    reader.endArray();                    reader.close();                    return  trips;   }      
  • 20. Gson performance 87.3 ms 56 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1 10 Trips 100 Trips 500 Trips
  • 21. Gson performance 87.3 ms 56 KB 142.9 ms 399 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1 10 Trips 100 Trips 500 Trips
  • 22. Gson performance 10 Trips 100 Trips 500 Trips 87.3 ms 56 KB 142.9 ms 399 KB 459.2 ms 599 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1
  • 24. Jackson Offers 3 alternative methods for processing JSON (Streaming API, Tree Model, Data Binding) Default Jackson only handles strictly valid JSON but can be configured Provides simple readValue() and readTree() methods ObjectMapper caching  
  • 25. Jackson implementation example public  Trips  getTrips(  String  json  )  {          ObjectMapper  objectMapper  =  new  ObjectMapper();            return  objectMapper.readValue(  json,  Trips.class  );   }    
  • 26. Jackson performance 351 ms 146 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1 10 Trips 100 Trips 500 Trips
  • 27. Jackson performance 351 ms 146 KB 455 ms 386 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1 10 Trips 100 Trips 500 Trips
  • 28. Jackson performance 10 Trips 100 Trips 500 Trips 351 ms 146 KB 636 ms 837 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1 455 ms 386 KB
  • 30. Protocol Buffers Language and platform neutral mechanism for serializing structured data
  • 31. Protocol Buffers Language and platform neutral mechanism for serializing structured data You specify how you want the information you’re serializing to be structured by defining protocol buffer message types in .proto files
  • 32. Protocol Buffers Language and platform neutral mechanism for serializing structured data You specify how you want the information you’re serializing to be structured by defining protocol buffer message types in .proto files Each protocol buffer message is a logical record of information containing name- value pairs
  • 33. Protocol Buffers Language and platform neutral mechanism for serializing structured data You specify how you want the information you’re serializing to be structured by defining protocol buffer message types in .proto files Each protocol buffer message is a logical record of information containing name- value pairs .proto files are used to generate special source code which allows you to populate, serialize, and parse protocol buffer objects
  • 34. Protocol Buffers Language and platform neutral mechanism for serializing structured data You specify how you want the information you’re serializing to be structured by defining protocol buffer message types in .proto files Each protocol buffer message is a logical record of information containing name- value pairs .proto files are used to generate special source code which allows you to populate, serialize, and parse protocol buffer objects Protocol buffer messages are serialized into a tiny binary format. Serializing and parsing protocol buffer messages is much faster than JSON.
  • 35. Protocol Buffers .proto file package  TripsList;     option  java_package  =  "com.priceline.droidcon.model.proto";   option  java_outer_classname  =  "TripsProtos";     message  Trips  {    ...   }   message  Trip  {    ...   }   message  OfferDetails  {    ...   }   message  PrimaryOffer  {    ...   }   message  Customer  {    ...   }  
  • 36. Protocol Buffers .proto file package  TripsList;     option  java_package  =  "com.priceline.droidcon.model.proto";   option  java_outer_classname  =  "TripsProtos";     message  Trips  {    ...   }   message  Trip  {    ...   }   message  OfferDetails  {    ...   }   message  PrimaryOffer  {    ...   }   message  Customer  {    ...   }  
  • 37. Protocol Buffers .proto file package  TripsList;     option  java_package  =  "com.priceline.droidcon.model.proto";   option  java_outer_classname  =  "TripsProtos";     message  Trips  {    ...   }   message  Trip  {    ...   }   message  OfferDetails  {    ...   }   message  PrimaryOffer  {    ...   }   message  Customer  {    ...   }  
  • 38. Protocol Buffers .proto file package  TripsList;     option  java_package  =  "com.priceline.droidcon.model.proto";   option  java_outer_classname  =  "TripsProtos";     message  Trips  {    ...   }   message  Trip  {    ...   }   message  OfferDetails  {    ...   }   message  PrimaryOffer  {    ...   }   message  Customer  {    ...   }  
  • 39. Protocol Buffers implementation example public  List<Trip>  getListOfTrips(  byte[]  data  )  {   Trips  trips  =  Trips.parseFrom(  data  );              return  trips.getTripList();   }    
  • 40. Protocol Buffers implementation example public  List<Trip>  getListOfTrips(  byte[]  data  )  {   Trips  trips  =  Trips.parseFrom(  data  );              return  trips.getTripList();   }    
  • 41. Protocol Buffers implementation example public  List<Trip>  getListOfTrips(  byte[]  data  )  {   Trips  trips  =  Trips.parseFrom(  data  );              return  trips.getTripList();   }    
  • 42. Protocol Buffers performance 3.816 ms 264 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1 10 Trips 100 Trips 500 Trips
  • 43. Protocol Buffers performance 3.816 ms 264 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1 24.231 ms 352 KB 10 Trips 100 Trips 500 Trips
  • 44. Protocol Buffers performance 10 Trips 100 Trips 500 Trips 3.816 ms 264 KB 24.231 ms 352 KB 102.355 ms 1,728 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1
  • 47. FlatBuffers Efficient open-source, cross platform serialization library
  • 48. Efficient open-source, cross platform serialization library Similar to Protocol Buffers but allows you to access information without parsing the data which results in much better memory performance FlatBuffers
  • 49. FlatBuffers Efficient open-source, cross platform serialization library Similar to Protocol Buffers but allows you to access information without parsing the data which results in much better memory performance A schema let’s you define how you want to structure your data
  • 50. FlatBuffers Efficient open-source, cross platform serialization library Similar to Protocol Buffers but allows you to access information without parsing the data which results in much better memory performance A schema let’s you define how you want to structure your data FlatBuffer is a binary buffer containing data organized by offsets
  • 51. FlatBuffers Efficient open-source, cross platform serialization library Similar to Protocol Buffers but allows you to access information without parsing the data which results in much better memory performance A schema let’s you define how you want to structure your data FlatBuffer is a binary buffer containing data organized by offsets Faster than JSON and smaller memory footprint than Protocol Buffers
  • 52. FlatBuffers schema namespace  TripsList;     table  Trips  {    trips  :  [Trip];   }     table  Trip  {    ...   }     table  OfferDetails  {    ...   }     ...     root_type  Trips;      
  • 53. FlatBuffers schema namespace  TripsList;     table  Trips  {    trips  :  [Trip];   }     table  Trip  {    ...   }     table  OfferDetails  {    ...   }     ...     root_type  Trips;      
  • 54. FlatBuffers schema namespace  TripsList;     table  Trips  {    trips  :  [Trip];   }     table  Trip  {    ...   }     table  OfferDetails  {    ...   }     ...     root_type  Trips;      
  • 55. FlatBuffers schema namespace  TripsList;     table  Trips  {    trips  :  [Trip];   }     table  Trip  {    ...   }     table  OfferDetails  {    ...   }     ...     root_type  Trips;      
  • 56. FlatBuffers implementation example public  List<Trip>  getListOfTrips(  byte[]  data  )  {   Trips  trips  =  Trips.getRootAsTrips(  ByteBuffer.wrap(  data  )  );            List<Trip>  list  =  new  ArrayList<>();              for  (  int  i  =  0;  i  <  trips.tripsLength();  i++  )  {              list.add(  trips.trips(  i  )  );            }              return  list;   }      
  • 57. FlatBuffers implementation example public  List<Trip>  getListOfTrips(  byte[]  data  )  {   Trips  trips  =  Trips.getRootAsTrips(  ByteBuffer.wrap(  data  )  );            List<Trip>  list  =  new  ArrayList<>();              for  (  int  i  =  0;  i  <  trips.tripsLength();  i++  )  {              list.add(  trips.trips(  i  )  );            }              return  list;   }      
  • 58. FlatBuffers implementation example public  List<Trip>  getListOfTrips(  byte[]  data  )  {   Trips  trips  =  Trips.getRootAsTrips(  ByteBuffer.wrap(  data  )  );            List<Trip>  list  =  new  ArrayList<>();              for  (  int  i  =  0;  i  <  trips.tripsLength();  i++  )  {              list.add(  trips.trips(  i  )  );            }              return  list;   }      
  • 59. FlatBuffers performance 10 Trips 1.304 ms 3.8 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1 100 Trips 500 Trips
  • 60. FlatBuffers performance 10 Trips 1.304 ms 3.8 KB 6.153 ms 6.944 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1 100 Trips 500 Trips
  • 61. FlatBuffers performance 10 Trips 100 Trips 500 Trips 1.304 ms 3.8 KB 6.153 ms 6.944 KB 13.704 ms 13 KB Incl. CPU Time Memory Allocation Tests were performed on a Motorola Nexus 6 running Android 5.1.1 Protocol Buffers On average 350% faster than Protocol Buffers
  • 62. Overall Time Results Gson Jackson Protocol Buffers Flat Buffers 459 ms 14 ms Note: Time results shown for 500 trips 102 ms 636 ms
  • 63. Our Selection FlatBuffers was faster and more efficient, but… Image credits: The Noun Project – Dalpat Prajapati
  • 64. Our Selection FlatBuffers was faster and more efficient, but… Our final decision was Protocol Buffers
  • 65. Our Selection FlatBuffers was faster and more efficient, but… Our final decision was Protocol Buffers ...it’s not the fastest, but it was the most optimal for us
  • 66. Our Selection FlatBuffers was faster and more efficient, but… Our final decision was Protocol Buffers ...it’s not the fastest, but it was the most optimal for us FlatBuffers is still a great way to serialize and deserialize data
  • 67. Wrap Up Don’t get lost in translation for serializing your data structures Image credits: The Noun Project – Hello Many
  • 68. Wrap Up Don’t get lost in translation for serializing your data structures Different options available (Gson → Jackson → Protocol Buffers → FlatBuffers)
  • 69. Wrap Up Don’t get lost in translation for serializing your data structures Different options available (Gson → Jackson → Protocol Buffers → FlatBuffers) FlatBuffers are the best balance of speed and memory efficiency (FlatBuffers won the battle, it did not win the war) Image credits: The Noun Project - Rediffusion