From time to time, I learn of "new" (in the sense of not known to me) optimization that RyuJIT or the LegacyJIT can take.
From a recent example, I learned, for instance, that:
For BCL ValueType primitives byte, sbyte, ushort, short, uint, int, ulong, long, IntPtr, UIntPtr, Guid cast via object to the type and use .Equals directly them directly; then rely on the Jit to elide the boxing - meaning the mostly completely inline (e.g. Guid doesn't; though isn't a virtual call)
Or in other words, that in this type of code-construct:
if (typeof(TKey) == typeof(byte))
{
return (byte)(object)key0 == (byte)(object)key1;
}
The JIT can omit the boxing all together.
As someone attempting to write correct yet readable code, this sort of information, of what the JIT can and can't do, is not available to the best of my knowledge.
Is there a way the a definitive list could be made that describes exactly which optimizations the JIT can make and under what circumstances?
From time to time, I learn of "new" (in the sense of not known to me) optimization that RyuJIT or the LegacyJIT can take.
From a recent example, I learned, for instance, that:
Or in other words, that in this type of code-construct:
The JIT can omit the boxing all together.
As someone attempting to write correct yet readable code, this sort of information, of what the JIT can and can't do, is not available to the best of my knowledge.
Is there a way the a definitive list could be made that describes exactly which optimizations the JIT can make and under what circumstances?