Details
-
Improvement
-
Status: Resolved
-
Blocker
-
Resolution: Fixed
-
None
-
None
-
None
Description
We have used two (de)serialization methods, such as JSON and Protocol Buffer. In a (de) serializable object, each attribute can be placed on the corresponding member variable or the member variable of the protocol buffer object.
For reducing the frequency of data copies, we have used the laze copy approach that delays copying values from the contents of PB object to member variables or vice versa. It is similar to copy-on-wrote (COW).
In many cases, however, this mechanism is actually burden rather than the performance benefit like the below code. Especially, this problem becomes more complicated if the wrapper class can be (de)serialized via both JSON and protocol buffer.
protected TableDescProto proto = TableDescProto.getDefaultInstance(); protected TableDescProto.Builder builder = null; protected boolean viaProto = false; @Expose protected String tableId; @Expose protected Path uri; @Expose protected TableMeta meta; . . public String getId() { // <- even a simple getter becomes very complicated. TableDescProtoOrBuilder p = viaProto ? proto : builder; if (tableId != null) { return this.tableId; } if (!p.hasId()) { return null; } this.tableId = p.getId(); return this.tableId; }
Therefore, I would like to propose the simplification of wrapper classes by eliminating the laze copy approach. My proposal is as follows:
- A wrapper class only keeps values in member variables when it is created.
- A wrapper class only builds the corresponding protobuf object when getProto() is called.
I think that the performance benefit has been very low. We should remove the lazy copy approach for more robust system.