Fix incorrectly configured recyclable memory stream pool sizes #225
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
The
NewtonsoftDocumentSerializer
makes use of aRecycableMemoryStreamManager
to efficiently use and re-use memory streams. However, the manager is configured in such a way as to be quite inefficient with memory.On construction, the
RecyclableMemoryStreamManager
takes three arguments:The last two are of interest. For pooling large buffers of memory, a series of pools is created with varying sizes. These sizes are (1 * Large Buffer Multiple), (2 * Large Buffer Multiple), etc. up to the Maximum Large Buffer Size. The idea being to have a fairly small variety of sizes to choose from, with the smaller pools being more densely populated than the larger pools.
Currently, the
NewtonsoftDocumentSerializer
uses 1MB for the Maximum Large Buffer Size and 4 bytes for the Large Buffer Multiple. This means that there are 262,144 pools created, each one 4 bytes larger than the previous. Having this amount of variance in pool sizes is not helpful, and is in fact quite costly. Around 12MB of memory is used just to track the pools.Results
Change the Large Buffer Multiple to 256kB and increase the Maximum Large Buffer Size to 2MB. This will result in the following 8 large buffer pools: