We recommend writing short and concise methods instead of lengthy and complex methods. The main reason is the jit mechanism of. net.
When a program written in C # code is running, two steps are required: 1) the C # compiler compiles the source code to the Il intermediate code; 2) CLR calls the JIT compiler to convert the Il code to the local machine code. These two steps will be apportioned throughout the application running process. CLR does not perform JIT compilation on the entire application when the application is started, but JIT compilation on the basis of methods. This can reduce the startup time of the program to a considerable extent, and also prevent the program from responding slowly due to a large amount of code that requires JIT compilation. The methods that are not called will not be compiled by JIT. Therefore, by writing code into multiple short and concise methods, we can reduce the workload for JIT compilation and try to improve the application performance.
The short and concise method also makes it easier for the JIT compiler to support enregistration. enregistration refers to which local variables are stored in registers instead of stacks, A small number of local variables will make it easier for the JIT compiler to make the most appropriate enregistration selection. At the same time, the simplicity of the control flow in the method also affects how the JIT compiler performs better enregistration.
The JIT compiler also makes decisions on the inline method. inline means that function calls are directly replaced with the code in the function body. For example, the get and set accessors In the attribute are considered as inline methods.
Thinking: With regard to get and set accessors of properties, I remember in Jeffrey's book, I once said that get and set accessors in Il will be converted into methods. Is it inline? What is the difference between the anonymous method in inner and C? If you know, please give us an explanation.