Unused VCL Units Profiler Tutorial: 3 - Removing Unused Units

Applies to AQTime 8.81, last modified on January 18, 2022

Once you locate the units that import unused units, you can open the application in the IDE and remove references to unused units. It is better not to delete the unit name, but to comment it out.

  • Open the sample application’s UnusedVCLUnitsDemo.dpr file in your compiler.
  • Navigate to the uses section and exclude (comment out) the names of the UnusedUnit and Classes units. The source code will look like this:

    Delphi

    {File: UnusedVCLUnitsTestDemo.dpr}
      
    library UnusedVCLUnitsDemo;


    uses
      SysUtils,
      // Classes, <- This unit is actually not used
      MainUnit in 'MainUnit.pas',
      UsedUnit in 'UsedUnit.pas';
      // UnusedUnit in 'UnusedUnit.pas'; <- This unit is actually not used

    {$R *.res}

    begin
    end.

  • In a similar way, exclude UnusedUnit from the uses section of MainUnit.pas:

    Delphi

    {File: MainUnit.pas}
      
    ...
      
    implementation

    uses
        UsedUnit, { UnusedUnit, } Windows;
      
        ...

  • Recompile your application.

You have removed the Classes and UnusedUnit units from the sample project. As a result, the size of the executable has decreased. However, the optimization is not over yet: Since units import each other, you should profile the new version of the executable to verify that all the unused units have been eliminated. To do this:

  • Open the application in AQTime. It will automatically update the list of modules in the Setup pane.
  • Ensure that Unused VCL Units Profiler is selected and the value of the Delphi version option corresponds to the IDE version.
  • Click Run on the Standard toolbar to start profiling.Select Run from Visual Studio’s AQTime menu to start profiling.Select Run With Profiling from Embarcadero RAD Studio’s AQTime menu to start profiling.
  • Wait for the analysis to complete and switch to the Report panel.

Reviewing the results in the Report panel, you can notice that more unused units were found.

Results of second profiling in the Report panel

Click the image to enlarge it.

Results of second profiling in the Report panel

Click the image to enlarge it.

Results of second profiling in the Report panel

Click the image to enlarge it.

The remaining unused unit is SysUtils. If you take a look at the Details panel, you will see that the SysUtils unit is imported by the application’s UnusedVCLUnitsDemo unit. Therefore, another correction of the application's sources and one more profiling are required:

  • Open the sample application’s UnusedVCLUnitsDemo.dpr file in your compiler.
  • Exclude (comment out) SysUtils from the uses section. The source code will look like this:

    Delphi

    {File: UnusedVCLUnitsDemo.dpr}
      
    library UnusedVCLUnitsDemo;


    uses
      // SysUtils,
      // Classes,
      MainUnit in 'MainUnit.pas',
      UsedUnit in 'UsedUnit.pas';
      // UnusedUnit in 'UnusedUnit.pas';

    {$R *.res}

    begin
    end.

  • Recompile your application.
  • Open the application in AQTime.
  • Ensure that Unused VCL Units Profiler is selected and the Delphi version option is set correctly.
  • Start profiling and wait for it to complete.

 

Results of third profiling in the Report panel

Click the image to enlarge it.

Results of third profiling in the Report panel

Click the image to enlarge it.

Results of third profiling in the Report panel

Click the image to enlarge it.

Finally, the Report panel states that all the units in the application are used and no redundant units are included. Optimizing the sample application with the Unused VCL Units profiler allowed you to decrease the size of the executable from 1153 to 605 kilobytes (the measurements are given for the application compiled with Delphi 2006).

Prev

See Also

Unused VCL Units Profiler

Highlight search results