Information Technology Reference
In-Depth Information
cation when it starts, the CLR invokes the JITer on a function-by-function
basis. This minimizes the startup cost to a reasonable level, yet keeps the
application from becoming unresponsive later when more code needs to
be JITed. Functions that do not ever get called do not get JITed. You can
minimize the amount of extraneous code that gets JITed by factoring code
into more, smaller functions rather than fewer larger functions. Consider
this rather contrived example:
public string
BuildMsg(
bool
takeFirstPath)
{
StringBuilder
msg =
new
StringBuilder
();
if
(takeFirstPath)
{
msg.Append(
"A problem occurred."
);
msg.Append(
"\nThis is a problem."
);
msg.Append(
"imagine much more text"
);
}
else
{
msg.Append(
"This path is not so bad."
);
msg.Append(
"\nIt is only a minor inconvenience."
);
msg.Append(
"Add more detailed diagnostics here."
);
}
return
msg.ToString();
}
The first time BuildMsg gets called, both paths are JITed. Only one is
needed. But suppose you rewrote the function this way:
public string
BuildMsg2(
bool
takeFirstPath)
{
if
(takeFirstPath)
{
return
FirstPath();
}
else
{
return
SecondPath();
}
}