by the current design/implementation, it is for 99%
the job of the JITer to optimize code.
That doesn't make sense at all. Why would Microsoft choose to have their
code optimized at runtime rather than at compile time?
In my case, the C# compiler is making IL for a single function that spans
~70 lines. I have rewritten that same function myself in IL in 30 lines.
My problem is more complex, but to give you a basic idea of what the C#
compiler makes vs. what I can code myself I'll give you an example:
here is the C# code for an 'Add' function:
private static int Add(int op1, int op2) {
return (op1 + op2);
}
when disassembled, that function looks like this:
..method private hidebysig static int32 Add(int32 op1,int32 op2)
{
.locals init (int32 retval)
IL_0000: ldarg.0
IL_0001: ldarg.1
IL_0002: add
IL_0003: stloc.0
IL_0004: br.s IL_0006
IL_0006: ldloc.0
IL_0007: ret
}
now here is some code I wrote, which does exactly the same thing:
..method private hidebysig static int32 Add(int32 op1,int32 op2)
{
ldarg.0 // push op1 on stack
ldarg.1 // push op2 on stack
add // add the 2 ops
ret // return
}
that's a ratio of 8 lines vs. my 4 lines. Which one will be faster?
Chris LaJoie