Comments (4)
Hi Ben!
I really like your current implementation A LOT. It is very readable, tailor-made for the use-case and very easy to reason about; with nice event hooks to observe the operations, and very useful debugging utilities.
With ArrayPool being an abstract class, things are a bit blurrier. The Shared implementation looks complex, with multi-core optimizations that might improve performance, but then, you would be relying on a singleton class that is heavily used internally by the runtime libraries (at least in the .Net Standard 2.0 libraries) and that might dwarf the optimizations. The non-shared implementation looks much simpler but is restricted to work internally with buffers that are sized in powers-of-two and last time I checked, protects concurrent access via a SpinLock; It may offer better performance, but personally I like more being able to directly inspect the code as in your current implementation.
Currently I am using the library to implement extremely efficient channel multiplexing. I am concurrently serializing hundreds of large DTOs to Recyclable streams and the data slicing to enable the multiplexing is completely handled by your library, with zero-copy, zero-allocation. According to the profiler, now the "bottleneck" is curiously, on the Math.DivRem() operations that are done to locate the buffer to place a byte! I am really thankful.
I'm curious about your own thoughts? What are the reasons why you consider such a change?
from microsoft.io.recyclablememorystream.
It's been asked a couple of times, so I created this as a place for discussion.
from microsoft.io.recyclablememorystream.
Adding to what @sgorozco said:
-
ArrayPool<byte>.Shared
only caches up to 32 arrays of the same size (not counting thread-locals). It would be extremely easy to exhaust/flood the shared array pool if RMS started using it. -
ArrayPool<byte>.Create()
returns aConfigurableArrayPool<byte>
, which can return buffers twice as large as desired, making it very easy to waste memory.
RMS would need to use its own array pool implementation, which wouldn't simplify anything. However, it may be worth it to open up an extension point to let users control allocation. If we used ArrayPool<byte>
as the interface, RMS should throw if either of the default implementations are used, and document how the custom pool should behave.
from microsoft.io.recyclablememorystream.
DOTNET_SYSTEM_BUFFERS_SHAREDARRAYPOOL_MAXARRAYSPERPARTITION can be used to set the number of arrays cached.
I think there should be a way to configure RMS to use the ArrayPool<byte>.Shared
also.
from microsoft.io.recyclablememorystream.
Related Issues (20)
- Is there a plan to contribute to the dotnet/runtime? HOT 4
- FeatureRequest: Add opt-in possibility to zeroed-out buffers HOT 10
- Continous benchmarking HOT 1
- Multiple StreamManagers in referenced libraries - how to find total memory usage HOT 1
- Large pool limit should apply to whole pool, not each slot HOT 1
- Humanitarian Organization Team mbrgi
- ResponseTime is almost doubled with RecyclableMemoryStream. HOT 5
- Question: GetStream copy existing buffer use case HOT 1
- How effective is this package for buffers that are usually smaller than 256 bytes? HOT 1
- Breaking changes at 3.0.0 version break OfficeOpenXml NuGet package HOT 11
- Guideline about cryptography with RMS HOT 5
- Unclear Documentation for MaximumFreeSmallPoolBytes
- Upgrade blocker: Recent change of GetStream() to return RecyclableMemoryStream instead of MemoryStream HOT 1
- why just pool MemoryStream HOT 2
- FileStreamResult: ObjectDisposedException: Cannot access a disposed object. HOT 4
- For many small stream writes, RecyclableMemoryStream is slower than other implementations HOT 4
- ETW event source is not working HOT 2
- Use of RecyclableMemoryStreamManager with Confluent.Kafka HOT 2
- RecyclableMemoryStream.TryGetBuffer causes infinite loop when UseExponentialLargeBuffer is true HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from microsoft.io.recyclablememorystream.