Increase default JSON string buffer capacity - #3125
sb123sb123 wants to merge 1 commit into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
eamonnmcmanus
left a comment
There was a problem hiding this comment.
Thanks for taking this on! It does need a small adjustment.
| public String toString() { | ||
| try { | ||
| StringBuilder stringBuilder = new StringBuilder(); | ||
| StringBuilder stringBuilder = Gson.newJsonStringBuilder(); |
There was a problem hiding this comment.
Unfortunately this doesn't work because we need to be able to build a subset of Gson that includes JsonElement but does not include Gson. That's why the build for this PR is failing. You could move the newJsonStringBuilder() method here as a quick fix. That's not a great home for it, but I don't see a better one without introducing a new class.
Fixes #2645
Why
The implicit JSON string output paths still started with the default StringBuilder capacity of 16. For a 33-character string, the JSON output is 35 characters but the builder grows to a capacity of 70, causing an avoidable resize and copy. This is the remaining issue discussed after #2852 switched the implicit output path from StringWriter to StringBuilder.
What changed
Tests
The full multi-module mvn clean verify was not run because the shared Windows G: drive was concurrently space-constrained; the affected gson module completed verify.
AI assistance
AI assistance was used during issue/PR investigation and implementation. The submitted diff was reviewed and the listed checks were run before submission.