Compiling Optimizations
From VbGORE Visual Basic Online RPG Engine
Compiling options in Visual Basic, when used correctly, can greatly speed up not only your code, but the compiling of your code. For example, the vbGORE server, if you try compiling it with no options ticked, you'll notice it takes a very, very long time to compile, but simply ticking the Remove Array Bounds Checks and Remove Integer Overflow Checks will make a huge difference. This is because the compiler wont have to add in those checks, which is also what speeds up the program. It is important that you do not tick things that will mess up your program. For the server, it is usually safe to assume, "If it works for me, then I don't care" because you are not (usually) distributing it. But for the client, you want it to run as flawlessly as possible. At the same time, some optimizations will actually decrease the number of errors you have, so it is important to know which does what.
Contents |
[edit] Before you start
It is always recommended you do plenty of testing from the Visual Basic IDE (coding interface). The IDE catches most problems, more then what the EXE will report. Do not ignore these! Every time you get an error, fix it! Even if this means adding a check for valid variables / parameters, or better yet, fixing the problem before it even happens.
Failure to fix the problems and just ignore them will result in misbehaving code with these optimizations ticked, which can make debugging a released product very difficult.
[edit] Assume No Aliasing
Aliasing is when a variable is referenced twice in the same place. An example of this is the following code:
Dim I As Long Call MyPro(I, I) Public Sub MyPro(ByRef Arg1 As Long, ByRef Arg2 As Long) ... End Sub
Although I is one variable, it is referenced in both Arg1 and Arg2. If you do not do this in your code, it is safe to tick this box.
[edit] Remove Array Bounds Checks
This will check whether or not an index is within the range of an array before using the array, along with if the correct number of dimensions are used. Examples:
Dim b(1 to 3) As Byte b(4) = 1 'Out of bounds (upper) b(0) = 1 'Out of bounds (lower) b(1,1) = 1 'Out of bounds (incorrect number of dimensions)
Ticking this option will prevent these checks, and in result, also prevent giving error messages for this error.
It is highly recommended that you keep this option ticked.
[edit] Remove Integer Overflow Checks
This will check if your numeric variables are in the correct value scope. If you tick this option, whenever a variable goes over the limit, it will "roll over" to the opposite side of the scope. Example:
Dim b As Byte Dim i As Integer '0 presents the lowest value in the variable, and 255 the unsigned size of the variable b = 256 'Overflow, b will now equal (0 + (256 - 255)), or 1. b = 300 'Overflow, b will now equal (0 + (300 - 255)), or 45. i = 32800 'Overflow, i will now equal (-32767 + (32800 - 65536)), or -32736
Turning off this option will greatly speed up your code, but can easily result in very strange variable values that can easily screw up your program. For important variables and variables that have access to dangerous code (Loops, Sleep API, Counters, etc), always make sure you know the exact range it will be using, and put your own overflow checks if needed.
It is highly recommended that you keep this option ticked.
[edit] Removing Floating Point Error Checks
By default, Visual Basic will add in checks on floating point variables (Singles and Doubles) to make sure they are within a valid range. Removing this option will disable checking for valid floating point operations, such as division by 0.
It is highly recommended that you keep this option ticked.
[edit] Allow Unrounded Floating Point Operations
Turning on this optimization will prevent floating point variables being rounded to the nearest decimal of accuracy. This will speed up operations with floating point variables, but may give a variable to an accuracy you did not expect. Be careful when ticking this when looking for very precise floating-point values.
If you do not use many accuracy-critical floating point operations (vbGORE, for example, does not), it is recommended to tick this.
[edit] Remove Safe Pentium FDIV Checks
Turning off this optimization disables checking for safe Pentium floating-point division, along with turns off the generation of special code for Pentium processors with the FDIV bug. Ticking this value will speed up your code a little, but in rare occasions, will cause code to produce slightly incorrect results on Pentium processors with the FDIV bug.
The FDIV bugs were first reported in late 1994, and it is estimated that only one in every 9 billion floating point operations are slightly affected. Intel decided to recall the defective processors. Any Pentium with a clock speed of 120 Mhz or higher is too new to have this bug. Unless you are designing for a very specific, rare case where you must use a very old Pentium, it is recommended that you always tick this optimization.



