Applies to AQTime 8.80, last modified on June 13, 2019

The Unused VCL Units profiler helps you determine which VCL units are actually not used in your application and decrease the size of the executable (or library) by excluding those units. The profiler supports Delphi applications created with the Delphi compiler from version 3 to XE3. The profiler is static, it analyzes the application’s source code and does not require the application to be running.

This topic provides an overview of the Unused VCL Units profiler.

About Working With VCL Units

The Delphi compiler automatically includes all units listed in the uses clause to the compiled executable / library file. However, the linker does not ascertain whether the program actually calls any of the procedures from the included unit. This can occur if you drop a component onto a form to take a look at it and then you delete the component from the form. The Delphi IDE does not remove the component’s unit from the uses clause.

The problem is that the Delphi compiler generates the initialization and finalization procedures for every included unit. Besides user-defined initialization and finalization code, the compiler adds its own code to manage reference count variables. Therefore, the initialization and finalization procedures are generated even if the unit does not have corresponding sections. Thus, if a unit is not actually used, then only its initialization and finalization sections are called.

How the Profiler Works

The Unused VCL Units profiler includes a database that contains information about the number of procedures used by initialization and finalization sections of each standard VCL unit. This profiler compares the number of procedures exported by a unit with the number specified for this unit in the database. If the unit exports more functions than the database indicates, the profiler considers it as a used unit. If the number of the exported procedures equals the number specified in the database, the unit is included in the list of unused ones.

The profiler scans the source code (namely, the uses section) of each user unit and of each standard unit referred by the application. Therefore, in order to use the profiler, you should specify the paths to the standard IDE units in AQTime’s Project Search Directories and Search Directory dialogs. Each dialog has a Get Defaults button to help you specify the standard unit paths faster.

The number of procedures in the initialization section varies from one Delphi version to another. To specify which Delphi version was used to build the profiled application, use the Delphi version option.

Recognition Issues

The described analysis algorithm has one drawback. If a unit is used in an application but does not export more functions than required for its initialization and finalization, the profiler still reports it as “unused”.

This situation is possible in the following cases:

  • If a unit contains constants and variables.

  • If a unit declares class types that are used in other units.

  • If a unit declares one or several classes that only contain inherited methods and do not define their own methods.

To resolve the issue, you can exclude these units from the analysis. This can be done by specifying unit names either in the Ignore units with names containing option, or in the IgnoredUnits text file. The Ignore units with names containing option defines a semicolon-separated list of words that can contain the names of units to be skipped.

Thus, you can exclude not only individual units, but also groups of units, whose names match the specified pattern. For instance, by specifying const, you can skip both MyConstants and SrvConst units. The IgnoredUnits.txt file is located in the <AQTime>\Bin\Extensions folder and defines the names of the units to be skipped for a particular version of the compiler.

All units whose names match the value of the Ignore units with names containing option or whose names are listed in the IgnoredUnits.txt file are considered used.

General Procedure of Removing Unused Units

After the profiling is over, the profiling results list all units imported by the application and indicate which units are not used (for more information on profiling results, see Unused VCL Units Profiler Results). When the profiler recognizes a unit in your application as unused, you can remove all references to it from your application’s source code. To explore the unit’s source code, double-click its name in the Report or Details panel and switch to the Editor panel.

Keep in mind that units can import one another, therefore to remove all unused units, you should verify your application several times. The general sequence of iterations is as follows:

  1. Profile the application with the Unused VCL Units profiler.

  2. Open the application in the IDE and remove the previously found unused modules.

  3. Recompile the application.

  4. Profile the application with the Unused VCL Units profiler once again.

  5. If more unused modules are found, repeat the actions starting from step 2.

For example, let’s assume your project contains two unused units - Buttons and Graphics (standard VCL units). The Buttons unit uses some of the procedures from the Graphics one. So, the number of exported procedures for Graphics is greater than the number specified for this unit in the database. Therefore, the Unused VCL Units profiler considers the Graphics unit as used. After the first launch, the profiler will report that only the Buttons unit is unused. Remove this unit from your project, recompile your application and return to AQTime. After the second launch, the profiler will report that the Graphics unit is not used.

See Also

Unused VCL Units Profiler
Unused VCL Units Profiler Results - Overview
Unused VCL Units Profiler Options
Unused VCL Units Profiler Tutorial

Highlight search results