Nalaka1693 / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

Improve toString performance by over 40% #69

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Attached is a patch to improve the toString performance by over 40% (tested 
encoding large JSON objects that serialized > 100k in size). This is done in 
two ways:

1. Replace StringBuffer with StringBuilder, since the latter is not 
synchronized on every method. This is safe because the StringBuilder does not 
escape the toString internals and therefore cannot be accessed by any other 
thread.
2. Instead of child objects returning their own toString representation and 
appending that to the string representation of the parent object for nested 
types, pass along the StringBuilder as an accumulator when visiting all the 
objects. This eliminates creating many temporary strings.

Original issue reported on code.google.com by michael....@gmail.com on 31 Mar 2012 at 10:22

Attachments:

GoogleCodeExporter commented 8 years ago
Thank you Michael. I'll merge it to the project.

Original comment by fangyid...@gmail.com on 4 Jul 2012 at 5:49

GoogleCodeExporter commented 8 years ago
I made a similar change in r218; sadly, we can't use StringBuilders as long as 
we're trying to maintain JDK 1.2 compatibility.

Thanks!

Original comment by jon.cham...@gmail.com on 10 Aug 2013 at 4:09