HighTechTalks DotNet Forums  

Performance of VS 2005 RC

Dotnet Framework (Performance) microsoft.public.dotnet.framework.performance


Discuss Performance of VS 2005 RC in the Dotnet Framework (Performance) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
John
 
Posts: n/a

Default Performance of VS 2005 RC - 10-20-2005 , 08:11 AM






Hello,

I am building the application which is writes in C# and needs goog
performance.

I optimalize it in the .NET Framework .NET 1.1. Then I am start using of
..NET beta Framework 2.0 beta 1, than beta 2 and now Release canditate.

But now performence decreased. I am using generics for usin collection and I
am not using foreach if I not have to.

Is bag in VS 2005 RC or I must go back to .NET 1.1 for fast code in .NET C#.

Thank John

Reply With Quote
  #2  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: Performance of VS 2005 RC - 10-20-2005 , 12:57 PM






John <John (AT) discussions (DOT) microsoft.com> wrote:
Quote:
I am building the application which is writes in C# and needs goog
performance.

I optimalize it in the .NET Framework .NET 1.1. Then I am start using of
.NET beta Framework 2.0 beta 1, than beta 2 and now Release canditate.

But now performence decreased. I am using generics for usin collection and I
am not using foreach if I not have to.

Is bag in VS 2005 RC or I must go back to .NET 1.1 for fast code in .NET C#.
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Where is your performance bottleneck?

Note that using foreach doesn't significantly decrease performance in
most situations, and can even increase the performance in some
situations. More than that, it tends to give more easily readable code
- so I'd use it anywhere it's useful unless you can *prove* that in
that particular situation it's hurting performance significantly.

--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Reply With Quote
  #3  
Old   
john conwell
 
Posts: n/a

Default Re: Performance of VS 2005 RC - 10-25-2005 , 09:55 PM



Jon is right about the for vs foreach loops. foreach has a bit of overhead,
but unless your iterating about 25 million times you wont see a
difference...and even then its really small.

One common mistake that people make when migrating to 2.0 is to go Generics
crazy, and turn every arraylist and hashtable they have into a generic one.
but consider that the C# (or JIT, i'm not sure) compiler will take every
generic list and generate code to make it strongly typed. so every Interface
and object used to make an ArrayList will be duplicated in memory per type
the generic object is bound to.

This can cause a fairly significant increase in the applications memory
working set. The recomendations that i've read from MS is to use
List<object> for all your reference type collections and then go ahead and
create specific typed generics for your value types. This is because the
List<> class got some improvements in how it implements the IEnumerable that
make it more efficient than the ArrayList. But with List<object> you are
only creating one set if code in memory...for an object. and casting from a
specific type to and object and back is trivial.

"Jon Skeet [C# MVP]" wrote:

Quote:
John <John (AT) discussions (DOT) microsoft.com> wrote:
I am building the application which is writes in C# and needs goog
performance.

I optimalize it in the .NET Framework .NET 1.1. Then I am start using of
.NET beta Framework 2.0 beta 1, than beta 2 and now Release canditate.

But now performence decreased. I am using generics for usin collection and I
am not using foreach if I not have to.

Is bag in VS 2005 RC or I must go back to .NET 1.1 for fast code in .NET C#.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

Where is your performance bottleneck?

Note that using foreach doesn't significantly decrease performance in
most situations, and can even increase the performance in some
situations. More than that, it tends to give more easily readable code
- so I'd use it anywhere it's useful unless you can *prove* that in
that particular situation it's hurting performance significantly.

--
Jon Skeet - <skeet (AT) pobox (DOT) com
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Reply With Quote
  #4  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: Performance of VS 2005 RC - 10-26-2005 , 02:29 AM



john conwell <johnconwell (AT) discussions (DOT) microsoft.com> wrote:
Quote:
Jon is right about the for vs foreach loops. foreach has a bit of overhead,
but unless your iterating about 25 million times you wont see a
difference...and even then its really small.

One common mistake that people make when migrating to 2.0 is to go Generics
crazy, and turn every arraylist and hashtable they have into a generic one.
but consider that the C# (or JIT, i'm not sure) compiler will take every
generic list and generate code to make it strongly typed. so every Interface
and object used to make an ArrayList will be duplicated in memory per type
the generic object is bound to.
No, that's not true. Reference types all get a single implementation
shared between them, and then there's an implementation per value type.

It's worth making everything you can generic, not for performance
reasons, but for safety and readability.

--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Reply With Quote
  #5  
Old   
John
 
Posts: n/a

Default Re: Performance of VS 2005 RC - 10-26-2005 , 05:23 AM



Hello,

I was found problem. When I run application outside VS than it runs fast.

Thank all,
John


"Jon Skeet [C# MVP]" wrote:

Quote:
john conwell <johnconwell (AT) discussions (DOT) microsoft.com> wrote:
Jon is right about the for vs foreach loops. foreach has a bit of overhead,
but unless your iterating about 25 million times you wont see a
difference...and even then its really small.

One common mistake that people make when migrating to 2.0 is to go Generics
crazy, and turn every arraylist and hashtable they have into a generic one.
but consider that the C# (or JIT, i'm not sure) compiler will take every
generic list and generate code to make it strongly typed. so every Interface
and object used to make an ArrayList will be duplicated in memory per type
the generic object is bound to.

No, that's not true. Reference types all get a single implementation
shared between them, and then there's an implementation per value type.

It's worth making everything you can generic, not for performance
reasons, but for safety and readability.

--
Jon Skeet - <skeet (AT) pobox (DOT) com
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Reply With Quote
  #6  
Old   
john conwell
 
Posts: n/a

Default Re: Performance of VS 2005 RC - 10-26-2005 , 08:04 PM



god, i love MVPs.
Actually, no. Reference types dont all get one single implementation. Its
true that they do share SOME code between them, but SOME code will get
duplicated by type.

"Jon Skeet [C# MVP]" wrote:

Quote:
john conwell <johnconwell (AT) discussions (DOT) microsoft.com> wrote:
Jon is right about the for vs foreach loops. foreach has a bit of overhead,
but unless your iterating about 25 million times you wont see a
difference...and even then its really small.

One common mistake that people make when migrating to 2.0 is to go Generics
crazy, and turn every arraylist and hashtable they have into a generic one.
but consider that the C# (or JIT, i'm not sure) compiler will take every
generic list and generate code to make it strongly typed. so every Interface
and object used to make an ArrayList will be duplicated in memory per type
the generic object is bound to.

No, that's not true. Reference types all get a single implementation
shared between them, and then there's an implementation per value type.

It's worth making everything you can generic, not for performance
reasons, but for safety and readability.

--
Jon Skeet - <skeet (AT) pobox (DOT) com
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Reply With Quote
  #7  
Old   
Jon Skeet [C# MVP]
 
Posts: n/a

Default Re: Performance of VS 2005 RC - 10-27-2005 , 02:32 AM



john conwell <johnconwell (AT) discussions (DOT) microsoft.com> wrote:
Quote:
god, i love MVPs.
Actually, no. Reference types dont all get one single implementation. Its
true that they do share SOME code between them, but SOME code will get
duplicated by type.
In that case, MSDN is wrong. It states:
<quote>
Generics work a little differently for reference types. The first time
a generic type is constructed with any reference type, the runtime
creates a specialized generic type with object references substituted
for the parameters in the MSIL. Then, each time a constructed type is
instantiated with a reference type as its parameter, regardless of what
type it is, the runtime reuses the previously created specialized
version of the generic type. This is possible because all references
are the same size.
</quote>

I suggest you submit a correction... the above was taken from "Generics
in the Runtime (C# Programmers Reference)".

More importantly, I would want to see good evidence for using several
generics types being a *significant* performance problem in a real-life
app. Would you avoid using two different method overloads if only one
would do the job but in a less readable way, just because of the extra
JIT cost?

--
Jon Skeet - <skeet (AT) pobox (DOT) com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Reply With Quote
  #8  
Old   
AT
 
Posts: n/a

Default Re: Performance of VS 2005 RC - 10-27-2005 , 03:26 AM



Jon wrote:
Quote:
In that case, MSDN is wrong.
<snip>

I've looked into this a bit more now, and John appears to be right in
saying that not *all* code is shared (although the details are sketchy
about what isn't).

The following gives a lot of good guidelines:
http://blogs.msdn.com/kcwalina/archi.../15/89860.aspx

In particular, it states that the "penalty" (in terms of JIT time and
space) for creating constructed types with various difference reference
types as the type parameters is "modest but not zero" - the overall
recommendation is that it's fine to use them. It also states that while
constructed collections of value types are much more efficient after
JITting compared with, say, ArrayList, that *all* types benefit from
the lack of runtime casting.

Personally, I think the readability gain from it being absolutely
explicit what types are involved is so great that I'd have to see
benchmarked evidence that the cost of using generics was significant in
a particular situation in order not to use them.

Jon



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.