Game Development Reference
In-Depth Information
Being able to write a for loop with a constant iteration count will give the JIT com-
piler a lot more flexibility and scope for optimization.
Use Asynchronous Calls
The .NET platform offers mechanisms to provide both asynchronous and syn-
chronous execution. Typically, synchronous execution is used for the bulk of your
application, though some situations warrant an asynchronous model in order to
increase performance and responsiveness. An example would be downloading a
file from a network or the Internet, which is generally a processor-intensive task
depending on the size of the file. The file could be downloaded asynchronously
while the user interface displays the running process of the operation.
An asynchronous model can be extremely advantageous when used correctly, although
it can destroy your performance if used incorrectly.
Note
There is a small overhead penalty incurred when using asynchronous calls. When an asynchronous
call is invoked, the security state of the call stack is copied and attached to the thread that is exe-
cuting the asynchronous call. This penalty is insignificant if the callback executes a fair chunk of
code, or if the asynchronous calls are infrequently executed.
Efficient IO Buffer Sizes
The .NET framework provides a number of data buffers that inherit from
BufferedStream . These buffers have a default buffer size value, but you are able to
set the value to any size that you want. Even though you have this freedom, in
almost every case you will be getting sub-optimal performance unless you have the
buffer size set to a value between 4000 and 8000 bytes. Generally, the only time
where a large buffer size is efficient occurs when a very predictable size is being
managed, such as files that are usually around the same size.
Minimize the Working Set
Managed code takes care of many low-level responsibilities and handles them
transparently, but managed code does not always handle things in the most effi-
cient way possible. External assemblies are loaded into the main application
domain when they are used for the first time, which increases memory usage and
decreases performance by a slight amount. Therefore, it is important to minimize
the number of assemblies that you use in order to keep the working set small.
 
Search Nedrilad ::




Custom Search