TLDR: without garbage 20% speed for serialization is possible and create will be nullified.
Old Protostuff:
min:74.54
max:4899.673
average:86.04783316078326ms deviation:8.080333160783255ms
-----------------------------------------------------------------------------
min:429.057
max:2079.188
average:465.73040217391167ms deviation:17.9744021739117ms
-----------------------------------------------------------------------------
min:643.0495
max:5948.684
average:694.1958037129713ms deviation:27.579303712971296ms
-----------------------------------------------------------------------------
Old json/dsl-platform:
min:44.296
max:6901.2685
average:49.83894883720957ms deviation:3.9214488372095744ms
-----------------------------------------------------------------------------
min:610.2865
max:5257.732
average:656.3769124178714ms deviation:22.289412417871404ms
-----------------------------------------------------------------------------
min:826.356
max:15202.3155
average:892.2987436997346ms deviation:36.36324369973454ms
-----------------------------------------------------------------------------
Old json/dsl-platform/databind (not currently included in bench)
min:55.5685
max:3643.4955
average:62.5230743507717ms deviation:4.6225743507717ms
-----------------------------------------------------------------------------
min:610.268
max:4916.0535
average:652.778143735286ms deviation:20.228643735286028ms
-----------------------------------------------------------------------------
min:818.764
max:13084.1555
average:885.4443308497441ms deviation:32.60333084974411ms
-----------------------------------------------------------------------------
After that I've added few changes discussed here.
In Serializer I've changed input signature from
S deserialize(byte[])
byte[] serialize(S)
into
S deserialize(byte[], int)
void serialize(S, OutputSteam)
I've introduced inherited ByteArrayOutputStream for access to underlying buffer
I've removed copy from JavaBuiltIn.mediaTransformer so it doesn't create useless garbage.
Rerun the tests for those three codecs...
Protostuff remained almost the same (+15 for serialization)
json/dsl-platform remained almost the same (-25 for serialization)
New json/dsl-platform/databind codec which can bind to an existing POJO improved a lot (this is equivalent of json/dsl-platform but instead of translating from existing POJO to DSL POJO, it uses existing POJO directly)
min:0.007
max:4.379
average:0.00952261257168601ms deviation:5.226125716860115E-4ms
-----------------------------------------------------------------------------
min:550.659
max:1193.018
average:578.8223589951363ms deviation:12.746358995136234ms
-----------------------------------------------------------------------------
min:812.383
max:16727.2635
average:878.1641930719179ms deviation:36.50219307191787ms
So it still generates garbage, but only on deserialization - I also tried deserializing into an existing instance, but there was no major difference, it still generated garbage (which is ok since it contains nested collections).
My take on this changes...
I think bench is certainly improved, since we can now introduce other libraries, such as SBE, FlatBuff and CNP without too much objections. The resulting comparison is much closer to the real world use case when somebody has an existing POJO and wants to use different codec for transport.
This also makes bench more POJO friendly and code-gen unfriendly, but I think that represents majority of use cases. Since conversion is being tracked and timed, it's fine to display results as such. We can reduce code-gen unfriendliness by allowing transformation into existing instances... but this too will create garbage (unless someone goes to the extreme).
Regards,
Rikard