Replies: 1 comment 4 replies
-
After some research, I found a code from this question: using SharpLab.Runtime;
[JitGeneric(typeof(int))]
[JitGeneric(typeof(object))]
public class A<T>
{
public static int X;
public static class B
{
public static int C() => X;
}
} That also generates similar pattern of assembly: A`1+B[[System.Int32, System.Private.CoreLib]].C()
L0000: mov ecx, 0x1b43c650
L0005: xor edx, edx
L0007: call 0x0f585a70
L000c: mov eax, [eax+4]
L000f: ret
A`1+B[[System.__Canon, System.Private.CoreLib]].C()
L0000: push ebp
L0001: mov ebp, esp
L0003: push eax
L0004: mov [ebp-4], ecx
L0007: mov edx, [ecx+0x20]
L000a: mov edx, [edx]
L000c: mov edx, [edx+8]
L000f: test edx, edx
L0011: je short L0015
L0013: jmp short L0021
L0015: mov edx, 0x1b43d35c
L001a: call 0x0f429aa0
L001f: mov edx, eax
L0021: mov ecx, edx
L0023: call 0x0f409940
L0028: mov eax, [eax+4]
L002b: mov esp, ebp
L002d: pop ebp
L002e: ret And from the answers I could assume that it is trying to access method table using the type parameters, because it is accessing different type |
Beta Was this translation helpful? Give feedback.
4 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.
Uh oh!
There was an error while loading. Please reload this page.
-
While I was experimenting with alloc-free Linq implementation, I found some interesting behavior, when I call generic method in pattern like
GenericMethod<GenericStruct<Class>>
, the benchmark performance went exceptionally poor.I did some experiment and made a small reproducible example. I used SharpLab to inspect JitAsm from this code:
Then I get this result:
The first two is for class and shares same code made with
__Canon
, which is understandable. Third example is inlined, which is ideal. But forth one! This creates huge chunk even though generic argument is not used at all inMyStruct
. Can anyone share the knowledge of what might have caused this? Thank you!Edited: Update example for readability
Beta Was this translation helpful? Give feedback.
All reactions