Most programmers compile their VB programs using the default
advanced compiler settings. If you know about these settings, you may be able to
change them to improve the performance of your compiled application.
You can find VB's compiler settings on the Compile tab of the Project
Properties dialog box, which you can display by selecting ProjectName Properties
from the Project menu. Click on the Advanced Optimizations button to set these
compiler options, as described below.
Assume No Aliasing
An alias is when a program
refers to the same variable (i.e., the same memory location) by two different
names. It can occur when you use global variables and pass procedure arguments
ByRef. Here's an example:
Dim var1 As Long
Sub MySub(var2 As
var2 = 1 ' Refers to the
memory location of
because var1 was passed to
procedure ByRef (the default).
2 ' Refers directly to the
location of var1.
If your program doesn't use aliases, select the Assume No Aliasing option to
permit the compiler to apply optimisations that it couldn't use if aliases were
present, thus speeding program execution.
Remove Array Bounds Checks
When your code
accesses an array element, VB normally checks to make sure the array element
exists; if it doesn't, it triggers a run-time error. For example:
Dim MyArray(100) As Integer
MyArray(200) = 25 ' Error - element
200 does not exist.
If you're confident this error will not occur--for example, if your code uses
the UBound and LBound functions to ensure that only legal array elements are
accessed--you can select the Remove Array Bounds Checks option for faster,
smaller compiled code. (Be careful: If this option is selected and your
code writes to a nonexistent array element, it can result in erratic program
behavior or a crash.)
Remove Integer Overflow Checks
By default, VB
checks the results of every calculation involving integer data types (Byte,
Integer, and Long) to ensure that the result doesn't exceed the range of the
data type. Selecting the Remove Integer Overflow Checks option disables these
checks and speeds integer calculations. (Beware: If an overflow does
occur, the calculation will produce incorrect results without a warning or
Remove Floating Point Error Checks
point error checks do the same thing for calculations involving the floating
point data types (Single and Double). Select the Remove Floating Point Error
Checks option to disable these checks with the same benefits and potential
problems as described above for integer overflow checks.
Allow Unrounded Floating Point Operations
When you select the Allow Unrounded Floating Point Operations option,
VB can perform certain operations with floating point data more efficiently. The
downside is that when you compare floating point values, they may be considered
unequal when, in fact, you expect them to be equal.
Remove Safe Pentium FDIV Checks
Pentium CPUs have a bug that produces slightly inaccurate results when
performing floating point divisions. VB's default is to check for and correct
By selecting the Remove Safe Pentium FDIV Checks option, you disable the
check, and your code will perform floating point divisions faster. These old
CPUs are pretty scarce these days, so this option is usually a safe one to
Author's note: You should apply the advanced compiler options
described in this tip carefully, and only if you understand the potential
effects on your program.
Peter Aitken has been programming with Visual Basic since Version 1.0. He
has written numerous books and magazine articles on Visual Basic and other
computer and programming topics.