When I was downloading the SP1 of .NET 3.5 months before, I did not realized that there are some CLR improvements in that release apart from some new features such as ADO.NET data services, improved WCF, etc. The improvements are expected to be in .NET 4.0 (CLR 4.0?), however .NET 3.5 SP1 has some CLR improvements:
- Improved application start-up performance (good news for WinForm applications).
- JIT code optimizations which improves end-to-end application performance.
- Opting managed code run in ASLR mode.
- Improved NGen.
- 20-45% performance improvements of WPF applicaiton without any code change.
- ClickOnce improvements.
I am more instrested in JIT optimization done in SP1. Let us see those improvements.
Inlining and Structs
Inline Method: Place a method’s body into the body of its callers and remove the method (function pointer). This is an explicit option in C++, however C# (.NET) doesn’t has, because it is in CLR’s hand.
For those, who don’t know about inline method, here the example:
1 2 3 4 5 6 7 8 9 |
|
The major benefit of the above inline method is the number of IL code generated for “inline” method which inherently give performance benefit. Since, inline is in CLR’s control, it does not treat a method as inline for the following:
- Methods greater than 32 bytes of IL.
- Methods with “while”/”switch”.
- Methods with “struct” argument(s).
- Virtual methods.
- Methods handling exception-handling.
In 3.5SP1, methods with “struct” argument are treated as “inline” if it satisfies other 4 constraints.
Improved Assertions
Null and range check, typeof check and comparisons have been improved.
Branch Straightening
JIT compiler now able to straighten the code branch based on common code path and fall-through code path justification. Based on this, fall-through codes are moved further down. Based on Surupas Biswas article, there was 10% improvement in throughput in some ASP.NET benchmarks.
Let us see more about NGen improvements and ASLR mode usage in another post.