First of all, it looks like you're compiling in debug mode, so the IL output isn't going to be optimized (partly because you may want to set breakpoints and inspect intermediate values, although I can't see why that would be a factor here). However, compiling in release mode only removes one of the locals, and I'm not sure why the other one is kept around (I suspect that the call to ignore isn't being completely optimized away).

In general is there a reason (other than curiosity) that you're concerned about the generated IL? I would be shocked if this had any actual performance impact (and in fact the JITter may be able to remove write-only locals, so the generated machine code might not even be affected).

By on 6/28/2011 8:08 AM ()

Apparently I have misunderstood what the ignore statement does or how it should be used.

if I change the AddInputParameter function by removing the |> ignore then the code generated does not contain the additional locals. Really do not understand that one.

But then I need to add the |> ignore to the calls to the function or I get a warning from the compiler.

How could, or can, the function be written so the |> ignore statement is not needed?

By on 7/3/2011 6:05 AM ()

Hi Dennis,

I think you should just use ignore within the function. The fact that the resulting code uses a local is an unexpected code generation quirk, but it seems extremely unlikely to present any real world performance degradation.

-Keith

By on 7/3/2011 6:48 AM ()

Thanks for the response.

Yes I was in debug mode, mainly for a couple other methods but I happened to notice this one and it is small and simple enough for an example.

Anyway, changing to release mode resulted in the same IL.

Not a performance issue, just curios.

I assume the the JIT can optimize the unused locals out, does it? I have no idea.

Thanks again.

By on 6/28/2011 10:08 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper