Title: Reduce memory consumption when repeatedly calling WritableJson.toByteArray · Issue #49428 · spring-projects/spring-boot · GitHub
Open Graph Title: Reduce memory consumption when repeatedly calling WritableJson.toByteArray · Issue #49428 · spring-projects/spring-boot
X Title: Reduce memory consumption when repeatedly calling WritableJson.toByteArray · Issue #49428 · spring-projects/spring-boot
Description: Enhancement request Hi, we are using LogstashStructuredLogFormatter in our projects and it has affected the performance because the garbage collector is running a lot. After analyzing the allocated memory we have detected that the Writab...
Open Graph Description: Enhancement request Hi, we are using LogstashStructuredLogFormatter in our projects and it has affected the performance because the garbage collector is running a lot. After analyzing the allocated...
X Description: Enhancement request Hi, we are using LogstashStructuredLogFormatter in our projects and it has affected the performance because the garbage collector is running a lot. After analyzing the allocated...
Opengraph URL: https://github.com/spring-projects/spring-boot/issues/49428
X: @github
Domain: redirect.github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Reduce memory consumption when repeatedly calling WritableJson.toByteArray","articleBody":"**Enhancement request**\nHi, we are using `LogstashStructuredLogFormatter` in our projects and it has affected the performance because the garbage collector is running a lot. After analyzing the allocated memory we have detected that the `WritableJson.toByteArray` method is the one to blame.\n\nAs far as I can see, you are using 2 buffers in memory for the same thing:\n\n```java\ndefault byte[] toByteArray(Charset charset) {\n\tAssert.notNull(charset, \"'charset' must not be null\");\n\ttry (ByteArrayOutputStream out = new ByteArrayOutputStream()) {\n\t\ttoWriter(new OutputStreamWriter(out, charset));\n\t\treturn out.toByteArray();\n\t}\n\tcatch (IOException ex) {\n\t\tthrow new UncheckedIOException(ex);\n\t}\n}\n```\nThe 2 buffers are:\n1) `ByteArrayOutputStream` buffer.\n2) `OutputStreamWriter.se.bb` (a `ByteBuffer` inside the `StreamEncoder` inside the `OutputStreamWriter`)\n\nDo you think that you could use \"toJsonString().getBytes()\"? Or maybe use some kind of `org.springframework.core.io.buffer.DataBuffer` implementation?\n\nAlso, when you compare `WritableJson` with Jackson `ObjectMapper`, you see that the `ObjectMapper` includes a \"BufferRecycler\" to reduce the number of times that the garbage collection has to run.\n\nDo you think that you could use something similar?\n\nThanks!","author":{"url":"https://github.com/System25","@type":"Person","name":"System25"},"datePublished":"2026-03-05T12:40:13Z","url":"https://github.com/spring-projects/spring-boot/issues/49428"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f54fc209-be6c-3ec2-7f55-68ea1a692562 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CF92:1F05C8:1E3ED74:27C7242:6AEDA112 |
| html-safe-nonce | bf55adca653dec0801c201ca85f7333dac50cfb937a6ec425cd75e04b507fe4c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjkyOjFGMDVDODoxRTNFRDc0OjI3QzcyNDI6NkFFREExMTIiLCJ2aXNpdG9yX2lkIjoiNDcwOTQ5MTUzOTQ3MTg2ODE3OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f08b8313e6e788b28ac3530ad3ecc2420e903099fb8899c359de9762638dcdd4 |
| hovercard-subject-tag | issue:4027983447 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/spring-projects/spring-boot/49428/issue_layout |
| twitter:image | https://opengraph.githubassets.com/62aab182013078ebb6affcc06838e5a0b3dd72991c5b3cc135177af34d06393d/spring-projects/spring-boot/issues/49428 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/62aab182013078ebb6affcc06838e5a0b3dd72991c5b3cc135177af34d06393d/spring-projects/spring-boot/issues/49428 |
| og:image:alt | Enhancement request Hi, we are using LogstashStructuredLogFormatter in our projects and it has affected the performance because the garbage collector is running a lot. After analyzing the allocated... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | System25 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9f51e3b6c7a190e426e641ae15acbc58dd1ac2003e96b58879bbc298e213dbf3 |
| turbo-cache-control | no-preview |
| go-import | github.com/spring-projects/spring-boot git https://github.com/spring-projects/spring-boot.git |
| octolytics-dimension-user_id | 317776 |
| octolytics-dimension-user_login | spring-projects |
| octolytics-dimension-repository_id | 6296790 |
| octolytics-dimension-repository_nwo | spring-projects/spring-boot |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 6296790 |
| octolytics-dimension-repository_network_root_nwo | spring-projects/spring-boot |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7060660810b587033ea861b8aa67beb72c8e6542 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width