Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / June 2006

Tip: Looking for answers? Try searching our database.

Readings on clr optimization?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ole Nielsby - 09 Jun 2006 23:17 GMT
What's the best litterature on how the clr optimizes things,
low-level?

I'm writing a continuation-style interpreter for a Lisp-flavour
language, and I feel my attempts of tuning it for performance
are shots in the fog.

Things I'd like to know are:

- how clever is the clr at inlining virtual calls? constructors?
 (can I use deep class hierarchies for very frequently constructed
 objects without taking a performance hit?)

- what happens to memory management when I use lots of
  weak refernces?

- what's the overhead of using interface pointers and methods?
 How are interface methods resolved? (Given an inherently
 multiple-inheritance data model, will I get more performance
 from mashing it into a single-inheritance hierarchy by creating
 lots of parallel branches, or using interfaces?

- are there things I should know about generics... operations
  that look simple in C# but get compiled into long-winded
  calls?

- and, I'd like the full story about tail calls and verifiable code

Thanks/Ole N.
Shawn B. - 15 Jun 2006 22:21 GMT
> What's the best litterature on how the clr optimizes things,
> low-level?

I have 3 books on my shelf:

http://www.amazon.com/gp/product/0201734117/
http://www.amazon.com/gp/product/0735621632/
http://www.amazon.com/gp/product/1861006292/

These three books will cover everything you need to know to answer the
questions in this post.

> - how clever is the clr at inlining virtual calls? constructors?
>  (can I use deep class hierarchies for very frequently constructed
>  objects without taking a performance hit?)

You can use deep class hierarchies as much as you want but I don't know
about the performance hit.  If you have frequently constructed objects you
might look into using a custom object pool.  I use them extensively (with
Generics) in our system and it makes a noticeable difference.  You may not
notice the server application running faster but you will notice a more
consistant CPU utilization lower than constantly creating thousands of
object repetitively per second/minute/whatever.

I haven't written anything about creating a custom object pool with C# but
Oliver Sturm has and it is almost identicle to the one I came up with
(conceptually) but only slightly different implementation (8-part series):
http://www.sturmnet.org/blog/archives/2005/10/18/object-pooling8/

If I remember correctly, virtual calls are not inlined.  Regarding
Constructors: Quote from MSDN2:
(http://msdn2.microsoft.com/en-us/library/w59wc6da.aspx)

The compiler cannot inline a call to a constructor if the class has a static
constructor. The compiler cannot inline a call to any member function if the
class is a value type, has a static constructor, and does not have an
instance constructor. The common language runtime may inline the call, but
the compiler cannot.

> - what happens to memory management when I use lots of
>   weak refernces?

Weak references are special objects that allow you to track references that
may have been garbage collected, without keeping a reference to it (thus
preventing garbage collection).  There aren't many implication with memory
management using WR unless you abuse it or do something wrong.  In short, WR
really help you when used correctly.  See:
http://msdn.microsoft.com/msdnmag/issues/1200/GCI2/

Keep in mind, if an object or valuetype (or array) consumes more than 80,000
bytes then the memory manager will not "defrag" the memory to allow the heap
to contain contiguous free memory.  This is for performance reasons.  I
absolutely do not know how to monitor the memory heap or memory degragger,
but I *guess* that an object holding references to other objects that
cumulatively hold more than 80,000 bytes doesn't count unless it is the
one-very-same-object.  However, you might want to keep this in mind and do
some of your own research (and benchmarking/profiling) to see what works for
you.  Using lots of valuetypes or a collection of value or a large array
will reach the 80k limit more than references of thousands of other objects
will (*I think*).  Perhaps someone from MS can confirm.

> - what's the overhead of using interface pointers and methods?
>  How are interface methods resolved? (Given an inherently
>  multiple-inheritance data model, will I get more performance
>  from mashing it into a single-inheritance hierarchy by creating
>  lots of parallel branches, or using interfaces?

Interface methods are virtual and thus are not inlined.

> - are there things I should know about generics... operations
>   that look simple in C# but get compiled into long-winded
>   calls?

I don't know.  What I do know is that a generic call is more or less a
"template" that when used for the first time against a type, a copy of it
using the specific type is created in memory and that copy is used for the
same type subsequently (I'm over simplifying the description here).  Each
different type will get a different copy.  The end result really doesn't
appear to be much more different than if it wasn't using a generic in the
first place but to specifically answer your question, I cannot be more
specific.  There is plenty of information on Generics (especially in the
ECMA spec for C# 2.0) and you alway of .NET Reflector to inspect your code
after compiling it.

> - and, I'd like the full story about tail calls and verifiable code

That's a big story.  I don't have time to write it.  Refer to the books at
the top of this reponse.

Thanks,
Shawn
Ole Nielsby - 16 Jun 2006 00:20 GMT
>> What's the best litterature on how the clr optimizes things,
>> low-level?
[quoted text clipped - 4 lines]
> http://www.amazon.com/gp/product/0735621632/
> http://www.amazon.com/gp/product/1861006292/

Thanks... the last one - "Advanced .NET Programming" by
Simon Robertson - seems like it might fill some of my needs.

Ole N.
john conwell - 20 Jun 2006 22:41 GMT
Funny...Those are my 3 favorite advanced .Net books!

One other i'd suggest looking at is "Improving .Net Application Performance
and Scalability".  Its really big, but has TONS of little perf treasures in
it.  MSDN has it on their site.

> > What's the best litterature on how the clr optimizes things,
> > low-level?
[quoted text clipped - 87 lines]
> Thanks,
> Shawn

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.