Understanding Safe Optimization

AutoCAD AutoLISP & Visual LISP

 
Understanding Safe Optimization
 
 
 

Choosing the Safe Optimize option reduces the amount of compiler optimization but protects your code against compiler-induced errors. Safe optimizing prevents runtime uncertainty that could cause an optimized program to fail, even though the source code seems to be correct. For example, imagine the following situation:

  • The function symbol fishlips is defined by defun and used somewhere in your code. This is a typical candidate for link optimization.
  • In another segment of your code, a variable named fishlips is assigned using (setq fishlips expression).

Now there are two possible conditions. If the value assigned through setq is intended to alter the definition of the function fishlips, direct linking will prevent this from happening. The first definition will be referenced directly and cannot be changed by the setq function. On the other hand, if the identical names are handled independently, fishlips can be linked without creating incorrect code.

If safe optimizing is on, the compiler will always stay on the safe side, even if you explicitly request that fishlips be directly linked. This may result in less efficient code, but it ensures code correctness. If safe optimizing is off, you can override the compiler's recommendation to link fishlips indirectly. You are responsible for the link option.

The Safe Optimize mode is on by default. Be sure you fully understand the consequences before you turn it off.