spray / spray-json

A lightweight, clean and simple JSON implementation in Scala
Apache License 2.0
974 stars 190 forks source link

+ JsonPrinter : allow a length to be provided for string builder #104

Closed tootedom closed 10 years ago

tootedom commented 10 years ago

Hi there,

Is it possible to allow for the specification of the size of the buffer used by the CompactPrinter and the PrettyPrinter. I noticed that the default size of 16chars is used, which causes a larger number of expansions to occur, increasing the amount memory allocations and TLAB pressure:

Here is an screen shot for a load test run of the default 16 chars

stringbuilderexpand

Here's the same execution, but being allowed to specify the size of the internal buffer:

stringbuilderexpandreduction


Maybe there's another way to address the sizing of the internal buffer. But I thought I'd highlight the expandCapacity impact.

thanks /dom

sirthias commented 10 years ago

Yes, allowing for a sizeHint is definitely a good idea. Thanks!

jrudolph commented 10 years ago

Increasing the default value would probably also make sense.

sirthias commented 10 years ago

Increasing the default value would probably also make sense.

Yes, indeed. Maybe 256 or 512?

sirthias commented 10 years ago

Fixed by https://github.com/spray/spray-json/commit/f33e846b95d8e9b20a8aeb4e2ca74fd2f34206fc. Thanks!