Printing to ByteBuffer (bytes) #11

Merged
merged 1 commit into from Jan 10, 2017

Conversation

Projects
None yet
3 participants
@vkostyukov
Contributor

vkostyukov commented Jan 9, 2017

As discussed in circe/circe#536 and finagle/finch#676 this PR introduces jacksonPrintBytes that prints directly into ByteBuffer.

I run some benchmarks and the results are quite surprising. The throughput is never better when printing to bytes, but the allocation rate is significantly lower (2x for case classes). Not sure I can reasonably explain neither why allocations are nearly the same when printing int arrays nor why throughput isn't improved. Although, I think it's a reasonable first step in binary printing.

[info] Benchmark                                                              Mode  Cnt       Score       Error   Units
[info] PrintingBenchmark.printFoosC                                          thrpt   20    2894.216 ±   120.682   ops/s
[info] PrintingBenchmark.printFoosC:·gc.alloc.rate.norm                      thrpt   20  454564.587 ±  1799.636    B/op

[info] PrintingBenchmark.printFoosCJBytes                                    thrpt   20    3418.018 ±    50.857   ops/s
[info] PrintingBenchmark.printFoosCJBytes:·gc.alloc.rate.norm                thrpt   20  259067.149 ±    71.022    B/op

[info] PrintingBenchmark.printFoosCJString                                   thrpt   20    3547.072 ±    55.888   ops/s
[info] PrintingBenchmark.printFoosCJString:·gc.alloc.rate.norm               thrpt   20  464377.531 ±     2.872    B/op

[info] PrintingBenchmark.printIntsC                                          thrpt   20   18770.557 ±   360.538   ops/s
[info] PrintingBenchmark.printIntsC:·gc.alloc.rate.norm                      thrpt   20   74504.088 ±     0.173    B/op

[info] PrintingBenchmark.printIntsCJBytes                                    thrpt   20   35936.390 ±   962.170   ops/s
[info] PrintingBenchmark.printIntsCJBytes:·gc.alloc.rate.norm                thrpt   20   38496.047 ±     0.093    B/op

[info] PrintingBenchmark.printIntsCJString                                   thrpt   20   39662.014 ±   634.973   ops/s
[info] PrintingBenchmark.printIntsCJString:·gc.alloc.rate.norm               thrpt   20   42384.042 ±     0.082    B/op

@vkostyukov vkostyukov referenced this pull request in finagle/finch Jan 9, 2017

Closed

String-less encoding #676

@travisbrown

This comment has been minimized.

Show comment
Hide comment
@travisbrown

travisbrown Jan 9, 2017

Member

Thanks! I'm on the road for the next couple of hours but should be able to get these merged and 0.7.0-M2 published from the airport after that.

Member

travisbrown commented Jan 9, 2017

Thanks! I'm on the road for the next couple of hours but should be able to get these merged and 0.7.0-M2 published from the airport after that.

@codecov-io

This comment has been minimized.

Show comment
Hide comment
@codecov-io

codecov-io Jan 9, 2017

Current coverage is 87.25% (diff: 100%)

Merging #11 into master will increase coverage by 0.79%

@@             master        #11   diff @@
==========================================
  Files            11         11          
  Lines            96        102     +6   
  Methods          87         93     +6   
  Messages          0          0          
  Branches          5          5          
==========================================
+ Hits             83         89     +6   
  Misses           13         13          
  Partials          0          0          

Powered by Codecov. Last update 1ba0880...56852cb

codecov-io commented Jan 9, 2017

Current coverage is 87.25% (diff: 100%)

Merging #11 into master will increase coverage by 0.79%

@@             master        #11   diff @@
==========================================
  Files            11         11          
  Lines            96        102     +6   
  Methods          87         93     +6   
  Messages          0          0          
  Branches          5          5          
==========================================
+ Hits             83         89     +6   
  Misses           13         13          
  Partials          0          0          

Powered by Codecov. Last update 1ba0880...56852cb

@vkostyukov

This comment has been minimized.

Show comment
Hide comment
@vkostyukov

vkostyukov Jan 9, 2017

Contributor

Thanks @travisbrown! I think it would be also nice to update README (w.r.t. benchmark results) at some point (when Circe's printing to bytes is also available).

Contributor

vkostyukov commented Jan 9, 2017

Thanks @travisbrown! I think it would be also nice to update README (w.r.t. benchmark results) at some point (when Circe's printing to bytes is also available).

@travisbrown

This comment has been minimized.

Show comment
Hide comment
@travisbrown

travisbrown Jan 9, 2017

Member

One quibble: what do you think about jacksonPrintByteBuffer, for consistency with the new prettyByteBuffer in circe-core, and to reserve the Bytes names for possible future Array[Byte] versions?

Member

travisbrown commented Jan 9, 2017

One quibble: what do you think about jacksonPrintByteBuffer, for consistency with the new prettyByteBuffer in circe-core, and to reserve the Bytes names for possible future Array[Byte] versions?

@vkostyukov

This comment has been minimized.

Show comment
Hide comment
@vkostyukov

vkostyukov Jan 10, 2017

Contributor

@travisbrown Agreed. Let me update this.

Contributor

vkostyukov commented Jan 10, 2017

@travisbrown Agreed. Let me update this.

@travisbrown

This comment has been minimized.

Show comment
Hide comment
@travisbrown

travisbrown Jan 10, 2017

Member

Great, thanks!

Member

travisbrown commented Jan 10, 2017

Great, thanks!

@travisbrown travisbrown merged commit 00a6e91 into circe:master Jan 10, 2017

3 checks passed

codecov/patch 100% of diff hit (target 86.45%)
Details
codecov/project 87.25% (+0.79%) compared to 1ba0880
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment