In case anyone is interested - this issue, which I raised on this list
back in March, has finally been resolved, thanks to the efforts
of an MS engineer after I raised a tech support incident.

To recap, I'd written a little test program that timed itself
accessing a field, both directly and through a wrapper property,
multiple times. The theory was that
if the JIT compiler was optimizing the way MS claim,
then the property access would be inlined so both times should should
be the same.  I wanted to test that behaviour - and actually found the
property access was slower on my machine. However a couple of other
people on the list tried out the program and found the times
were the same.

In fact the JIT compiler was inlining the property call. However, my
test was too crude. My loop looked like this.

for (int i=0 ; i < nIters ; i++)
{
        j = test.x;    // access some field.
}

Because test.x is never modified in the loop, it is theoretically possible
to remove the field access from the loop entirely. On my main machine
(an Athlon) the JIT compiler was detecting and doing this for the
direct field access. But when using the property, it was inlining
the property but not removing it from the loop.  Because the JIT compiler
produces processor-specific code, that behaviour won't necessarily
be the same on other processors - which is why other people found
identical times for field and property access.

Phew! (and thanks to Neil Kidd at MS who finally figured
out what was going on, as well as several people on this list
who made various suggestions)

Simon

---------------------------------------------------------------
Simon Robinson
http://www.SimonRobinson.com
---------------------------------------------------------------
----- Original Message -----
From: "Anil Patel" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 12, 2002 2:53 PM
Subject: Re: [DOTNET] JIT optimization and inlining (again)


Hi Simon,

If you looked at the IL for you exe, would that give any info about whether
any inlining
had been done.

Cheers, Anil

-----Original Message-----
From: Simon Robinson [mailto:[EMAIL PROTECTED]]
Sent: 12 March 2002 13:29
To: [EMAIL PROTECTED]
Subject: Re: [DOTNET] JIT optimization and inlining (again)


Cheers Mattias

I did use optimize on the command line
 (according to the docs that's the default anyway).
When running from VS.NET, doing Start without Debugging
does help quite a bit, although it's still slower than going
from command line.

Since my results are so different from Richard Birkby's I
wonder if there's some global .NET configuration setting
that could be mucking up optimizations? (Though I'm not
aware of having changed anything since I installed .NET).

My results were:
>From COMMAND LINE, JITting and ngen
----------------------------------------------

F:\Command Line Testing>csc /o+ perftest.cs
Microsoft (R) Visual C# .NET Compiler version 7.00.9466
for Microsoft (R) .NET Framework version 1.0.3705
Copyright (C) Microsoft Corporation 2001. All rights reserved.

F:\Command Line Testing>perftest
Today's date: 12/03/2002 13:17:22
FIRST TIME:
Accessing field: 00:00:00.1702448
Accessing field, and calling method: 00:00:00.1702448
Accessing property: 00:00:00.2503600
Accessing via property, and calling method: 00:00:00.2603744
SECOND TIME:
Accessing field: 00:00:00.1702448
Accessing field, and calling method: 00:00:00.1702448
Accessing property: 00:00:00.2503600
Accessing via property, and calling method: 00:00:00.2503600

F:\Command Line Testing>ngen perftest.exe
Microsoft (R) CLR Native Image Generator - Version 1.0.3705.0
Copyright (C) Microsoft Corporation 1998-2001. All rights reserved.
PerfTest, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

F:\Command Line Testing>perftest
Today's date: 12/03/2002 13:25:40
FIRST TIME:
Accessing field: 00:00:00.1702448
Accessing field, and calling method: 00:00:00.1702448
Accessing property: 00:00:00.1702448
Accessing via property, and calling method: 00:00:00.1702448
SECOND TIME:
Accessing field: 00:00:00.1702448
Accessing field, and calling method: 00:00:00.1702448
Accessing property: 00:00:00.1702448
Accessing via property, and calling method: 00:00:00.1702448

------------------------------------------------------

And from VS.NET, Start without Debugging (note longer time for
second attempt to access properties - it's not a fluke - I tried running
it several times).

Today's date: 12/03/2002 13:24:07
FIRST TIME:
Accessing field: 00:00:00.1602304
Accessing field, and calling method: 00:00:00.1602304
Accessing property: 00:00:00.2503600
Accessing via property, and calling method: 00:00:00.2503600
SECOND TIME:
Accessing field: 00:00:00.1702448
Accessing field, and calling method: 00:00:00.1702448
Accessing property: 00:00:00.3505040
Accessing via property, and calling method: 00:00:00.3505040
Press any key to continue


Simon

---------------------------------------------------------------
Simon Robinson
http://www.SimonRobinson.com
---------------------------------------------------------------
----- Original Message -----
From: "Mattias Sjögren" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 12, 2002 12:57 PM
Subject: Re: [DOTNET] JIT optimization and inlining (again)


Simon,

>Yet when I run the program, I repeatedly found that going
>via a wrapper property is much slower. This has rather surprised
>me, so I'm wondering if anyone else gets the same results.

If you didn't do an optimized build (/optimize), I suggest you try that.


>Interestingly, compiling and running
>from VS.NET slowed the program down quite a bit, even in
>the Release configuration. Anyone know why that would be?

If you use Debug / Start, JIT optimizations are disabled, regardless of the
configuration you use. Try Debug / Start without Debugging instead.


Mattias

===
Mattias Sjögren
[EMAIL PROTECTED]

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to