Monday, September 19, 2011

Improvements in the CLR Core in .NET Framework 4.5

Alongside all the exciting advents in Windows 8 and Metro apps, the .NET CLR is marching on. The next version of the CLR will feature several “internals” improvements, mostly in the performance area. Read on to learn about changes to the garbage collector, the JIT, and the native image generator engine in the next CLR.

Background mode for Server GC
Background GC is a neat feature introduced in CLR 4.0 to the Workstation GC flavor. It’s a little hard to explain without any background (pun intended), but the general gist is the following: while performing a full gen2 collection, the GC checkpoints at well-defined locations to see if a gen0/gen1 GC has been requested*. If a lower generation GC has been requested, the gen2 collection is paused, and the low-generation collection runs to completion before the gen2 collection resumes. This allows the code that caused the low-generation collection to resume its execution.

The new feature in the next CLR is that background GC is now supported on Server GC. (Recall that under Server GC, there is a GC heap for each processor and a separate GC thread for each processor.) There are additional changes in the GC, including a work-stealing mode in Server GC that allows GC threads to steal parts of the graph for marking if the workload is not distributed evenly.

Managed Profile Guided Optimization
If you have done any C++ work since Visual Studio 2003, you probably know about Profile Guided Optimization (PGO). In the C++ compiler, PGO is a special multi-step optimization mode, which relies on exercising the application through a set of scenarios with data collection enabled, and then recompiling the application with this data to optimize based on runtime information.

The same idea is now applied to managed code that has been NGEN-ed. A special command-line tool called mpgo.exe (which I can see integrated into Visual Studio like the C++ counterpart) instruments your .exe and embeds into it some runtime data that is subsequently used by ngen.exe to generate an optimized image.

You might wonder what kind of optimizations are enabled by MPGO. The only two that were disclosed at the time have to do with reducing the number of pages loaded from disk by organizing hot code together on the minimal number of pages, and with reducing the number of copy-on-write pages by organizing together on the minimal number of pages any data that will likely be overwritten at runtime.

Read more: All Your Base Are Belong To Us
QR: improvements-in-the-clr-core-in-net-framework-4-5.aspx

Posted via email from Jasper-Net