Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Improve toString performance #863

Closed
Simulant87 opened this issue Feb 22, 2024 · 2 comments
Closed

Enhancement: Improve toString performance #863

Simulant87 opened this issue Feb 22, 2024 · 2 comments

Comments

@Simulant87
Copy link
Contributor

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 added a commit to Simulant87/JSON-java that referenced this issue Feb 22, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Feb 22, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Feb 23, 2024
resulting in a faster toString generation.
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Feb 23, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Feb 23, 2024
@Simulant87 Simulant87 reopened this Feb 23, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Feb 24, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Feb 24, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Feb 24, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Feb 24, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Feb 25, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Mar 5, 2024
replacing a switch-case statement with few branches
by if-else cases
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Mar 5, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Mar 5, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Mar 10, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Mar 10, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Mar 10, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Mar 10, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Mar 10, 2024
Simulant87 added a commit to Simulant87/JSON-java that referenced this issue Mar 10, 2024
@nfaupel
Copy link

nfaupel commented Apr 9, 2024

I think this could be closed due to implementation complete in #867

@stleary
Copy link
Owner

stleary commented Apr 9, 2024

Closing due to implementation completed in #867

@stleary stleary closed this as completed Apr 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants