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

Reduce max size of recycled byte[]/char[] blocks by TextBuffer, ByteArrayBuilder #539

Closed
cowtowncoder opened this issue Jun 14, 2019 · 0 comments
Milestone

Comments

@cowtowncoder
Copy link
Member

Currently (up to Jackson 2.9) byte[] and char[] buffer recycling covers about 4 buffer types for both. I got a report that total retention per thread can exceed 600kB. This is bit more than I would expect for most usage (I'd have guessed 1/10 of that, maybe up to 64kB). Looking at what could be causing this, I think it must be the auto-expanding output buffers:

  1. TextBuffer uses CHAR_CONCAT_BUFFER, and for large output chunks may expand up to 256k chars, i.e. 512 kB
  2. ByteArrayBuilder uses BYTE_WRITE_ENCODING_BUFFER, with size up to 256kB

which are used via methods like:

String jsonStr = mapper.writeValueAsString(value);
byte[] jsonBytes = mapper.writeValueAsBytes(value);

Now: although we do want to keep buffers sizable enough, I think retention is something to balance too, and both should probably be capped at 128kB level.

There would be other possibilities too, like possibly allocating larger chunks, but only "returning" (and recycling) smaller chunks. But while that would be more optimal I am bit worried that code would be more complicated and possibly fragile; whereas simple size change is, well, simple and unlikely to cause issues (since behavior/logic won't change).

@cowtowncoder cowtowncoder changed the title Consider reducing max size of recycled byte[]/char[] blocks by TextBuffer, ByteArrayBuilder Reduce max size of recycled byte[]/char[] blocks by TextBuffer, ByteArrayBuilder Jun 14, 2019
@cowtowncoder cowtowncoder added this to the 2.10.0 milestone Jun 14, 2019
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

1 participant