-
-
Notifications
You must be signed in to change notification settings - Fork 819
Description
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:
TextBuffer
usesCHAR_CONCAT_BUFFER
, and for large output chunks may expand up to 256k chars, i.e. 512 kBByteArrayBuilder
usesBYTE_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).