Skip to content

Commit bd68dc8

Browse files
benaadamsdotnet-bot
authored andcommitted
Allow ArrayPool.Shared devirtualization (redux) (dotnet/coreclr#20637)
Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
1 parent 096e067 commit bd68dc8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Common/src/CoreLib/System/Buffers/ArrayPool.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ namespace System.Buffers
1919
/// </remarks>
2020
public abstract class ArrayPool<T>
2121
{
22+
// Store the shared ArrayPool in a field of its derived sealed type so the Jit can "see" the exact type
23+
// when the Shared property is inlined which will allow it to devirtualize calls made on it.
24+
private readonly static TlsOverPerCoreLockedStacksArrayPool<T> s_shared = new TlsOverPerCoreLockedStacksArrayPool<T>();
25+
2226
/// <summary>
2327
/// Retrieves a shared <see cref="ArrayPool{T}"/> instance.
2428
/// </summary>
@@ -33,7 +37,7 @@ public abstract class ArrayPool<T>
3337
/// optimized for very fast access speeds, at the expense of more memory consumption.
3438
/// The shared pool instance is created lazily on first access.
3539
/// </remarks>
36-
public static ArrayPool<T> Shared { get; } = new TlsOverPerCoreLockedStacksArrayPool<T>();
40+
public static ArrayPool<T> Shared => s_shared;
3741

3842
/// <summary>
3943
/// Creates a new <see cref="ArrayPool{T}"/> instance using default configuration options.

0 commit comments

Comments
 (0)