Article ID: 176435 - Last Review: May 13, 2003 - Revision: 2.0 PRB: Compiling to Native Code Can Be SlowThis article was previously published under Q176435 On This PageSYMPTOMS
When compiling a large project to native code, especially with
optimizations selected, the compile time may be so long as to give the
appearance of having "hung" the machine. Because there is no status bar to
indicate the progress of the compiler, the only indicator available is to
watch for hard drive activity, which may only occur once or twice a minute
as this is a CPU intensive activity.
CAUSE
This is by design. Compiling to native code takes more time than compiling
to p-code. There are some techniques suggested below for taking advantage
of some Visual Basic language features to speed up compile time.
MORE INFORMATION
Using the techniques outlined below can result in significantly faster
compile time. In some cases it has reduced compile time for large projects
from over an hour to less than 10 minutes.
Minimize the DotsWhen referencing objects in Visual Basic, you use the dot syntax '.' to navigate an object's hierarchy of collections, objects, properties, and methods. It is not uncommon to create very lengthy navigation strings. For example:The compiler must resolve each dot every time a dot is encountered. To write applications that compile quickly, minimize the use of dots when referencing an object. You can usually minimize the dots by analyzing the objects and methods available to you. For example, the above line of code can be shortened by removing the Item method (this is the default method for collections anyway, so you'll rarely use it in code) and by using the more efficient Range method: Use Set and With...End WithUsing the Set statement also allows you to shorten navigation strings and gives you a bit more control over your code. The following example uses the Dim and Set statements to create variables that refer to frequently-used objects:REFERENCES
Books Online, Programmer's Guide, Optimizing Objects
APPLIES TO
| Article Translations
|
Back to the top
