Skip to content

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

@cowtowncoder

Description

@cowtowncoder

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions