stleary / JSON-java

A reference implementation of a JSON package in Java.
http://stleary.github.io/JSON-java/index.html
Other
4.54k stars 2.56k forks source link

Enhancement: Improve toString performance #863

Closed Simulant87 closed 7 months ago

Simulant87 commented 9 months ago

The toString methods of JSONObject and JSONArray are not very fast, mostly because of the usage of StringWriter and the generic code to support an indent, although in the default toString case it is always 0.

You can compare the performance of the library e.g. with this comparison project, which also list the results in a graph: https://github.com/fabienrenaud/java-json-benchmark?tab=readme-ov-file#users-model

My suggestion is to improve the performance for the default toString method without indent by duplicating by using a StringBuilderinstead of a StringWriter.

nfaupel commented 7 months ago

I think this could be closed due to implementation complete in https://github.com/stleary/JSON-java/pull/867

stleary commented 7 months ago

Closing due to implementation completed in #867