_OPTI Optimization Report

Top  Previous  Next

 

Targets: All

 

This report pinpoints elements of the code that you can improve, resulting in better performance. With better performance, we here mean faster execution, not necessarily smaller code.

 

 

Missing “const” for unmodified string parameter (OPTI1)

 

This is a list of all string parameters that you can declare with the const directive, resulting in better performance since the compiler can assume that the parameter will not be changed. For example, for a long string the reference count for the string does not need to be updated on entry and exit to the function. For other types of strings, like WideString, the string may have to be copied when passed to the function.

 

Example:

 

clip0107

 

In this case, the parameter S should have the const directive, since it is never changed in the procedure. The compiler can generate code that is more efficient.

 

No warning is given for methods that are marked with the "override" directive. This is because they must follow the parameter list that the overridden method has.

 

__________________________________________________

 

Missing “const” for unmodified record parameter (OPTI2)

 

This is a list of all record parameters that you can declare with the const directive, resulting in better performance since the compiler can assume that the parameter will not be changed. Generally, if the parameter is larger than 4 bytes, and it doesn't need to be altered in the subroutine, const is more efficient. Also, it is a good idea to use CONST on parameters that aren't intended to be altered, so the compiler can catch those errors for you.

 

Example:

 

clip0108

 

In this case, the parameter R should have the const directive, since it is never changed in the procedure. The compiler can generate code that is more efficient.

 

No warning is given for methods that are marked with the "override" directive. This is because they must follow the parameter list that the overridden method has.

 

__________________________________________________

 

 

Missing "const" for unmodified array parameter (OPTI3)

 

This is a list of all array parameters that you can declare with the const directive, resulting in better performance since the compiler can assume that the parameter will not be changed.

 

No warning is given for methods that are marked with the "override" directive. This is because they must follow the parameter list that the overridden method has.

 

__________________________________________________

 

 

Array properties that are referenced/set within methods (OPTI4)

 

This is a list of all array properties that are referenced or set within methods of a class. Methods that include a reference to the property are listed.

 

For performance reasons it is faster to directly access the private array field. However, if the Get- or Set-method performs side effects, it makes sense to access the property.

 

For simple non-array properties, the compiler generates the same code for both access of the property or the field. Therefore, for normal properties there is no advantage in referencing the private field.

 

Example:

 

clip0109

 

__________________________________________________

 

 

Virtual methods (procedures/functions) that are not overridden (OPTI5)

 

This is a list of all methods that are declared as virtual, but that never are overridden. Since virtual methods have slightly worse performance than static methods, it is better to change these methods to static ones instead.

 

This section is also generated for multi-projects.

 

Recommendation:

 

Examine if these methods should really be overridden. If they belong to a base class, you should probably keep them virtual, so descendant classes can create their own implementations.

 

 

__________________________________________________

 

 

Local subprograms with references to outer local variables (OPTI6)

 

This section shows nestled local procedures, with references to outer local variables. Those local variables require some special stack manipulation so that the variables of the outer routine can be seen by the inner routine. This results in a good bit of overhead.

 

 

__________________________________________________

 

 

Subprograms with local subprograms (OPTI7)

 

This section lists subprograms that themselves have local subprograms. Especially when these subprograms share local variables, it can have a negative effect on performance.

 

 

__________________________________________________

 

 

Parameter is "var", can be changed to "out" (OPTI8)

 

This section lists parameters that are marked with the "var" directive, but that can be changed to "out".

Even if it may not improve performance, it improves the readability of the code and makes its intentions clearer.

 

 

See also:

 

R_GEN General Reports