|
|
|||
| H o m e | |||
|
|
O p t i m i z e P r o c e d u r e P e r f o r m a n c e By Michael McIntyre
You can optimize your application's performance in many ways. In this article learn how to optimize performance by the way you design your procedures. SizeProcedures that are too large or too small can decrease performance. Very large procedures – in excess of 1,000 lines - are not likely to benefit from JIT optimizations. A procedure is not compiled until the first time it is called. The JIT compiler can optimize a procedure while compiling it, for example generating inline code for small procedure calls, but not if the procedure is very large. Procedures that are too small can create excessive calls that decrease performance. The overhead can become very significant if a procedure called inside a loop does only one small task. If you include the body of a small procedure inside a loop you can avoid the overhead call mechanism. However, other factors must be considered too. Other places in your application cannot access that code. Also, if you duplicate the code elsewhere, you make maintenance more difficult, and you run the risk of update synchronization errors. Calling and ReturningCaller Location V.S. Procedure Location Unlike previous versions of Visual Basic the location of a procedure in relation to the calling code has no effect on performance. Return Code that uses the Return statement is optimized better than code using Exit Function, Exit Property, or Exit Sub. For functions use Return with an expression. For Subs and Properties use Return without an expression. Virtual Calls A call to any procedure declared by using the Overridable keyword is known as a virtual call. A virtual call takes about twice as much time as a call to a procedure that is not declared as Overrideable. This is because the common language runtime inspects the run-time type of the object to determine which override to invoke while a nonvirtual call can obtain all required information from the compile-time type. When designing classes define Overridable procedures only when there is a clear architectural advantage, and you should limit your calls as much as possible to NotOverridable procedures. ArgumentsThe performance difference between passing arguments ByRef and ByVal is usually insignificant. However, a large value type, such as a lengthy structure, can be more efficient to pass ByRef to avoid copying all the data. In the absence of a compelling reason to pass an argument ByRef, you should pass it ByVal. For more information, see Argument Passing ByVal and ByRef.
|
||
|
Copyright © 2001-2004 aZ Software Developers. All rights reserved. |
|||