I think that Partition.Trim(...)
from ArraySharedPool<T>
may be doing some unnecessary work
#101025
Labels
Partition.Trim(...)
from ArraySharedPool<T>
may be doing some unnecessary work
#101025
Hi, I was reading the source of
SharedArrayPool<T>
for curiosity and I think I may have found that it contains some old code which is irrelevant in the current implementation.Here the array length inside the
Partition
class is defined:runtime/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs
Line 391 in fa1164c
Here the trimming says that when there is high memory pressure it should clean a certain amount of elements:
runtime/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs
Line 452 in fa1164c
You can realize that the cleaning amount is the same value used to declare the array length, in other words, it cleans the entire array.
That is used here:
runtime/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs
Lines 483 to 487 in fa1164c
Then, why does the next line add additional elements to trim based on the rented array lengths and element size?
runtime/src/libraries/System.Private.CoreLib/src/System/Buffers/SharedArrayPool.cs
Lines 483 to 505 in fa1164c
It is already trimming the entire array, asking to trim more won't do anything as far as I know.
If this is not the case, could you please explain me the reasoning under that code? Thanks
The text was updated successfully, but these errors were encountered: