Skip to content

Enhancement: Improve toString performance #863

Description

@Simulant87

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions