C# Compiler Optimization Info, e.g., White Paper

G

Guest

Where can one find a discussion of the current and future optimizations that the C# compilers do? When I see things like the following I question my faith in csc being good at optimizing. The same kind of thing shows up in cordbg when looking at the JIT code for a similar example

% cat y.c

using System

class A
bool On { get { return true; }
public void Print()
if (On)
Console.WriteLine("On")




class ConditionalTest
static void Main(

A a = new A()
a.Print()



% csc /optimize+ y.c

Microsoft (R) Visual C# .NET Compiler version 7.10.3052.
for Microsoft (R) .NET Framework version 1.1.432
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved

% ildasm y.ex

..method public hidebysig instance void Print() cil manage

// Code size 19 (0x13
..maxstack
IL_0000: ldarg.
IL_0001: call instance bool A::get_On(
IL_0006: brfalse.s IL_001
IL_0008: ldstr "On
IL_000d: call void [mscorlib]System.Console::WriteLine(string
IL_0012: re
} // end of method A::prin



At least the compiler eliminates the "if" test when "On" is replaced with "true" in the test
 
G

Guest

Thanks. I'd seen that link before; it doesn't look very authoritative and it certainly doesn't provide much insight for current or future plans with the optimizer. It just lists a few optimizations without comment

As I said, the JIT compiler didn't seem to be doing so well either, at least for a very similar example that I looked at. That is why I am looking for information about what is actually done, and what's planned in the future. Without this information I have no reason to think that much of anything is being optimized, and some reason to think that it's not.
 
M

Mattias Sjögren

I'd seen that link before; it doesn't look very authoritative

It's a FAQ on Microsoft's developer website, written by C# team
members. In what way could it be any more authoritative?

and it certainly doesn't provide much insight for current or future plans with the optimizer. It just lists a few optimizations without comment.

What kind of comments are you looking for? There isn't much to say
about the current optimizations because there simply are so few of
them.

I don't know what the plans for the future are. You may have to wait
for a public beta to find out.

As I said, the JIT compiler didn't seem to be doing so well either, at least for a very similar example that I looked at.

How did you check that. Many people that don't use the debugger
correctly end up looking at unoptimized debug code and make incorrect
conclusions about the JIT abilities.

If you want more details on JIT optimizations, I suggest you visit the
group microsoft.public.dotnet.framework.performance. There are also
some good articles on this up on MSDN.



Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top