Information Technology Reference
In-Depth Information
It's not your responsibility to determine the best machine-level represen-
tation of your algorithms. The C# compiler and the JIT compiler together
do that for you. The C# compiler generates the IL for each method, and the
JIT compiler translates that IL into machine code on the destination
machine. You should not be too concerned about the exact rules the JIT
compiler uses in all cases; those will change over time as better algorithms
are developed. Instead, you should be concerned about expressing your
algorithms in a manner that makes it easiest for the tools in the environ-
ment to do the best job they can. Luckily, those rules are consistent with
the rules you already follow for good software-development practices. One
more time: smaller and simpler functions.
Remember that translating your C# code into machine-executable code is
a two-step process. The C# compiler generates IL that gets delivered in
assemblies. The JIT compiler generates machine code for each method (or
group of methods, when inlining is involved), as needed. Small functions
make it much easier for the JIT compiler to amortize that cost. Small func-
tions are also more likely to be candidates for inlining. It's not just small-
ness: Simpler control flow matters just as much. Fewer control branches
inside functions make it easier for the JIT compiler to enregister variables.
It's not just good practice to write clearer code; it's how you create more
efficient code at runtime.
 
Search WWH ::




Custom Search