-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ArrayPool does not resize based on user request #69641
Comments
Tagging subscribers to this area: @dotnet/area-system-buffers Issue DetailsArrayPoolDescriptionArrayPool (TlsOverPerCoreLockedStacksArrayPool) does not resize based on user request. TlsOverPerCoreLockedStacksArrayPool has constant value for arrays buckets. If those number of arrays is not enough then we get This approach is good enough if we can take and return array with low delay but can lead to issues in case when we need many arrays for a long time. I compare Repository with reproduce is available here - https://github.com/FrediKats/ArrayPoolAllocationReproduce. You can just run this project as-is and check allocations.
Configuration
dotMemory tracesDotMemory trace with changing allocation mode: Allocated objects while we using Allocated objects while we using pool form AnalysisSame issue was mentioned in #52098 (comment).
|
This is specifically why custom Array pool creation api was made, isn't it? Shared array pool is used across whole runtime and is used specifically with quick take-give back in mind. I doubt that tuning Shared for such a specific use case makes sense. |
ArrayPool
Description
ArrayPool (TlsOverPerCoreLockedStacksArrayPool) does not resize based on user request. TlsOverPerCoreLockedStacksArrayPool has constant value for arrays buckets. If those number of arrays is not enough then we get
GC.AllocateUninitializedArray
call:https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs#L24
This approach is good enough if we can take and return array with low delay but can lead to issues in case when we need many arrays for a long time. I compare
ArrayPool<T>.Shared
andArrayPool<T>.Create
. We ran into a problem while checking solution with genetic algorithm. In our case it needs to allocate about 3000 arrays (with constant size) for one iteration then we return it back to array pool and want to reuse in next iterations.Repository with reproduce is available here - https://github.com/FrediKats/ArrayPoolAllocationReproduce. You can just run this project as-is and check allocations.
Configuration
dotMemory traces
DotMemory trace with changing allocation mode:
Allocated objects while we using
ArrayPool<Vector2>.Shared
:Allocated objects while we using pool form
ArrayPool<Vector2>.Create
:Analysis
Same issue was mentioned in #52098 (comment).
The text was updated successfully, but these errors were encountered: