The performance of managed code exceeds the possibility of unmanaged code

Source: Internet
Author: User

I used to know that this is possible, but I have never been able to believe this (to be ridiculed by everyone ). Until you read
Jeffrey Richter's applied Microsoft. NET Framework programming is indeed
. NET Framework bible.

The following are some possibilities in the book:
The main reason is that JIT needs to understand the execution environment when compiling managed code into native code.
More than unmanaged code. (when the JIT compiler compiles the Il code
Native code at run time, the compiler knows more about the execution
Environment than unmanaged compiler wowould know .)

1. a jit compiler cocould detect that the application is running on
Pentium 4 and produce native code that takes advantage of any special
Instructions offered by the Pentium 4. Usually, unmanaged applications
Are compiled for the lowest-common-denominator CPU and avoid using
Special instructions that wowould give the application a performance
Boost over newer CPUs.
Originally, JIT can detect the new type of CPU and generate local code for the dedicated commands for these CPUs. On the contrary,
Unmanaged code to avoid compatibility issues, it generally avoids the exclusive commands of the new CPU, compilation
It is a local code oriented to the minimal universal set. In this way, the managed code performance of the exclusive command is fully utilized.
It must be superior. (Why did I not think of it ?!)

2. a jit compiler cocould detect that a certain test is always false on
Machine that it is running on. For example, consider a method with code
Like this:
If (numberofcpus> 1 ){
 
}
This code cocould cause the JIT compiler not to generate any CPU instructions
If the host machine has only one CPU. In this case, the native code has been
Fine-tuned for the host machine: the code is smaller and executes faster.
Ha, Richter mentioned this again. JIT can detect some Boolean tests that always return false, with a small amount of code,
The speed is faster.

3. the CLR cocould profile the Code's execution and recompile the IL into Native
Code while the application runs. The recompiled code cocould be reorganized
To reduce incorrect branch predictions depending on the observed execution
Patterns.
Code compiled based on the execution mode can be reorganized to improve the Branch Prediction Success rate! (Good JIT !)

Richter said that the above is only part of the possibility that the performance of the managed code exceeds the unmanaged code,
At present, the performance of managed code is good, and there is more potential for improvement. I firmly believe in this. net
The performance of the program is still very good. I have seen articles on this test before, and I have done some tests myself.

Finally, Richter's book is the best. net book I have ever read. It won't teach you how to write code,
Use controls, but it will give you some understanding of the internal secrets of. net. Now I can't help it anymore: d

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.