Make ArrayMemoryPoolBuffer a struct for less GC pressure. #123232
Unanswered
Danielku15
asked this question in
Ideas
Replies: 1 comment 3 replies
-
|
It is passed in the |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey there.
While troubleshooting the memory allocations in my networking code, I realized that the
MemoryPool<byte>.Sharedallocates new heap objects on everyRent.runtime/src/libraries/System.Memory/src/System/Buffers/ArrayMemoryPool.cs
Line 19 in 83d4dcd
runtime/src/libraries/System.Memory/src/System/Buffers/ArrayMemoryPool.ArrayMemoryPoolBuffer.cs
Line 8 in 83d4dcd
I wonder if this is really by-design, or just a historical oversight. When using
System.IO.Pipelines.PipeWriterthe underlying pipe will allocate objects from the configured MemoryPool triggering heap allocations on every write to the pipe.runtime/src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs
Lines 229 to 257 in 83d4dcd
Even Kestrel is affected by this: https://github.com/dotnet/aspnetcore/blob/8d9545796d3a6e0a7a21610d234ff5b28bada6d9/src/Servers/Kestrel/shared/DefaultSimpleMemoryPoolFactory.cs#L9-L17
For my own sake I now created an own
MemoryPool<T>which I pass into the related code areas and there I use astruct ArrayMemoryPoolBuffer : IMemoryOwner<T>.Beta Was this translation helpful? Give feedback.
All reactions