Replace System.IO.MemoryStream with Microsoft.IO.RecycableMemoryStream
Refer to http://www.codeproject.com/Articles/873615/Announcing-Microsoft-IO-RecycableMemoryStream
Microsoft.IO.RecyclableMemoryStream is a MemoryStream replacement that offers superior behavior for performance-critical systems. In particular it is optimized to do the following:
Eliminate Large Object Heap allocations by using pooled buffers Avoid memory leaks by having a bounded pool size Avoid memory fragmentation Provide excellent debuggability Provide metrics for performance tracking
This is now configurable from v4.0.38:
GetBuffer() API doesn't exist in PCL API.
Also the ProtoBufExtensions are only used in tests, not the ProtoBuf client.
But yeah it looks like further refactoring is going to be required to other code to take advantage of GetBuffer() internal byte pool.
To be PCL compatible and avoid extra deps the auditing was removed: https://github.com/ServiceStack/ServiceStack.Text/blob/master/src/ServiceStack.Text/RecyclableMemoryStream.cs#L1535