- Notifications
You must be signed in to change notification settings - Fork 5.2k
Closed
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issuePerformance related issue
Milestone
Description
Sometimes I use IntPtr
instead of Type
as a key (or part of a complex key) in Dictionary
.
Advantages is that it is a value type so I don't keep full blown Type
object alive, and GC likes value type fields more than ref ones because less references to follow.
But each time I need to get the value or check if a key exists I have to get Type
just to retrieve its handle value.
I suggest intrinsifying these calls:
[obj.]GetType().TypeHandle.Value typeof(T).TypeHandle.Value
How
In the following code JIT just compares method table pointer in the object header to the address of method table of String
type.
[MethodImpl(MethodImplOptions.NoInlining)] private static bool TestMtCheck(object obj) { return obj.GetType() == typeof(String); }
mov rax,7FEF61BDA88h cmp qword ptr [rcx],rax sete al movzx eax,al ret
It could do the same when getting type handle value :
[MethodImpl(MethodImplOptions.NoInlining)] private static IntPtr TestGetHandle(object obj) { return obj.GetType().TypeHandle.Value; } MethodImpl(MethodImplOptions.NoInlining)] private static IntPtr TestGetHandle() { return typeof(String).TypeHandle.Value; }
mov rax, qword ptr [rcx] ret
mov rax, 7FEF61BDA88h ret
category:cq
theme:type-intrinsics
skill-level:expert
cost:medium
xoofx, ReubenBond, dzmitry-lahoda, pentp, HFadeel and 10 more
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIenhancementProduct code improvement that does NOT require public API changes/additionsProduct code improvement that does NOT require public API changes/additionsoptimizationtenet-performancePerformance related issuePerformance related issue