Since protobuffers are a wonderful alternative for java serialisation, we have used it extensively. Also, we have used java builders as general data object. On examining the speeds of constructing an object using message builder ,forming the instance parameter, and normal java primitives forming the object, we found that for an object containing 6 primitive fields, constructing the object using builder(which is the parameter of the object) took 1.1ms whereas using java primitives took only 0.3ms! And for a list of 50 of such fields! Are builders heavy, that using them as general data object affects the speed of construction to this extent?
Below is the sample design i used for the analysis,
message PersonList
{
repeated Person = 1;
message Person
{
optional string name = 1;
optional int32 age = 2;
optional string place = 3;
optional bool alive = 4;
optional string profession = 5;
}
}
The java equivalent
Class PersonList {
List<Person> personList;
Class Person {
String name;
int age;
String place;
boolean alive;
String profession;
}
/* getters and setters*/
}