JSON-java icon indicating copy to clipboard operation
JSON-java copied to clipboard

Enhancement: Improve toString performance

Open Simulant87 opened this issue 1 year ago • 0 comments

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 StringBuilder instead of a StringWriter.

Simulant87 avatar Feb 22 '24 22:02 Simulant87