How are you getting the disassembly? Visual Studio has an option to suppress optimization when debugging managed code. Make sure that "Tools / Options / Debugging / Suppress JIT optimization on module load" is not enabled. I tried your code, and in fact I had to modify it to return the sum, otherwise the Go method was optimized away, but this is what I see when I disable 'Suppress JIT optimization':
// int i1 = _field1; 00000000 push esi 00000001 mov esi,dword ptr [ecx+4] // int i2 = this.Property; 00000004 mov edx,dword ptr [ecx+8] // return i1 + i2; 00000007 add esi,edx 00000009 mov eax, esi 0000000c ret Fernando Tubio ----- Original Message ----- From: "Keith Hill" <[EMAIL PROTECTED]> To: <ADVANCED-DOTNET@DISCUSS.DEVELOP.COM> Sent: Monday, October 30, 2006 2:06 PM Subject: [ADVANCED-DOTNET] Simple Property Getter Not Inlined I thought that property getters in optimized bits would get inlined in .NET but looking at 2.0 bits would indicate that they don't. For example, given this source: class App { private int _field1 = 7; private int _field2 = 14; static void Main() { new App().Go(); } public void Go() { int i1 = _field1; int i2 = this.Property; int sum = i1 + i2; } public int Property { get { return _field2; } } } The JIT'er generates the following x86 code: 00000000 push edi 00000001 push esi 00000002 push ebx 00000003 push ebp 00000004 mov esi,ecx 00000006 cmp dword ptr ds:[00928884h],0 0000000d je 00000014 0000000f call 78FB10C6 00000014 xor ebx,ebx 00000016 xor ebp,ebp 00000018 mov eax,dword ptr [esi+4] <<-- direct access to _field1 0000001b mov ebx,eax 0000001d mov ecx,esi 0000001f call dword ptr ds:[00929290h] <<-- calls this.Property getter 00000025 mov edi,eax 00000027 mov ebp,edi 00000029 nop 0000002a pop ebp 0000002b pop ebx 0000002c pop esi 0000002d pop edi 0000002e ret Did I just dream that I heard that simple property getters would get inlined by the JIT'er to be as fast as a direct field access? -- Keith Hill Windows PowerShell MVP =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com