Using a StringBuilder to improve the performance for the default toString methods without indent.
This duplicates a lot of code, as I assume you want to keep the existing public method interfaces accepting and returning a Writer for backwards compatibility. But is results in ~25% faster toString method, mostly used for serialisation.
Implementation for https://github.com/stleary/JSON-java/issues/863
Using a StringBuilder to improve the performance for the default
toString
methods without indent.This duplicates a lot of code, as I assume you want to keep the existing public method interfaces accepting and returning a
Writer
for backwards compatibility. But is results in ~25% fastertoString
method, mostly used for serialisation.I validated the performance with this project: https://github.com/fabienrenaud/java-json-benchmark
./run ser --libs ORGJSON
on my local machine result for the benchmark (thoughput measured in operations per second, higher is better):
currently latest library version 20240205:
Improved implementation from this PR: