Skip to content

Instantly share code, notes, and snippets.

View ocoanet's full-sized avatar

Olivier Coanet ocoanet

View GitHub Profile
00007FFD3B9D1970 sub rsp,28h
00007FFD3B9D1974 mov rdx,qword ptr [rcx+8]
00007FFD3B9D1978 mov ecx,dword ptr [rcx+10h]
00007FFD3B9D197B movsxd rcx,ecx
00007FFD3B9D197E mov eax,dword ptr [rdx]
00007FFD3B9D1980 mov rax,qword ptr [rdx+40h]
00007FFD3B9D1984 and ecx,dword ptr [rdx+48h]
00007FFD3B9D1987 add ecx,10h
00007FFD3B9D198A cmp ecx,dword ptr [rax+8]
00007FFD3B9D198D jae 00007FFD3B9D19B9
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T Read<T>(object array, int index)
{
IL.DeclareLocals(false, new LocalVar(typeof(byte).MakeByRefType()));
IL.Emit(OpCodes.Ldarg_0); // load the object
IL.Emit(OpCodes.Stloc_0); // convert the object pointer to a byref
IL.Emit(OpCodes.Ldloc_0); // load the object pointer as a byref
IL.Emit(OpCodes.Ldarg_1); // load the index
IL.Emit(OpCodes.Sizeof, typeof(object)); // get the size of the object pointer
00007FFD3B9D1930 mov rax,qword ptr [rcx+8]
00007FFD3B9D1934 mov edx,dword ptr [rcx+10h]
00007FFD3B9D1937 movsxd rdx,edx
00007FFD3B9D193A mov ecx,dword ptr [rax]
00007FFD3B9D193C mov rcx,qword ptr [rax+40h]
00007FFD3B9D1940 and edx,dword ptr [rax+48h]
00007FFD3B9D1943 lea eax,[rdx+10h]
00007FFD3B9D1946 lea eax,[rax*8+10h]
00007FFD3B9D194D movsxd rax,eax
00007FFD3B9D1950 mov rax,qword ptr [rcx+rax]
Method | Mean | Error | StdDev |
------------------- |----------:|----------:|----------:|
Publish | 0.8713 ns | 0.0116 ns | 0.0108 ns |
PublishPinning | 2.0890 ns | 0.0128 ns | 0.0119 ns |
IsAvailable | 0.7125 ns | 0.0029 ns | 0.0024 ns |
IsAvailablePinning | 2.0291 ns | 0.0136 ns | 0.0120 ns |
Method | Mean | Error | StdDev | Scaled | ScaledSD |
------------------ |----------:|----------:|----------:|-------:|---------:|
IndexerIL | 0.5106 ns | 0.0017 ns | 0.0015 ns | 1.00 | 0.00 |
IndexerUnsafe | 2.4546 ns | 0.0147 ns | 0.0131 ns | 4.81 | 0.03 |
IndexerArray | 1.5966 ns | 0.0048 ns | 0.0045 ns | 3.13 | 0.01 |
# Array + AggressiveInlining (OneToOneSequencedBatchThroughputTest)
Run: Ops: 276 157 615 - Duration: 3 621 (ms)
Run: Ops: 276 788 198 - Duration: 3 613 (ms)
Run: Ops: 277 759 098 - Duration: 3 600 (ms)
Run: Ops: 276 879 343 - Duration: 3 612 (ms)
Run: Ops: 276 884 548 - Duration: 3 612 (ms)
# IL + AggressiveInlining (OneToOneSequencedBatchThroughputTest)
Run: Ops: 373 840 259 - Duration: 2 675 (ms)
Run: Ops: 378 799 243 - Duration: 2 640 (ms)
# Array (OneToOneSequencedBatchThroughputTest)
Run: Ops: 112 706 424 - Duration: 8 873 (ms)
Run: Ops: 111 356 333 - Duration: 8 980 (ms)
Run: Ops: 110 476 411 - Duration: 9 052 (ms)
Run: Ops: 111 678 223 - Duration: 8 954 (ms)
Run: Ops: 111 526 217 - Duration: 8 967 (ms)
# Unsafe (OneToOneSequencedBatchThroughputTest)
Run: Ops: 206 831 897 - Duration: 4 835 (ms)
Run: Ops: 208 979 660 - Duration: 4 785 (ms)
public static int SumValues<T>(T source) where T : IHasValues
{
return source.Value1 + source.Value2;
}
public struct S : IHasValues
{
public int Value1
{
[MethodImpl(MethodImplOptions.NoInlining)]
00007FFEA25D04F0 sub rsp,28h
00007FFEA25D04F4 mov qword ptr [rsp+30h],rcx
00007FFEA25D04F9 lea rcx,[rsp+30h]
00007FFEA25D04FE call 00007FFEA25D00D8
00007FFEA25D0503 add eax,8888h
00007FFEA25D0508 add rsp,28h
00007FFEA25D050C ret
while (true)
{
// ISequenceBarrier _sequenceBarrier
long availableSequence = _sequenceBarrier.WaitFor(nextSequence);
// IBatchStartAware _batchStartAware
_batchStartAware?.OnBatchStart(availableSequence - nextSequence + 1);
while (nextSequence <= availableSequence)
{