Optimized Pascal compilation time

I was helping a customer to migrate from Delphi 5 to Delphi 2006 for some time ago.

It was almost only to reopen and compile the project except for some minor changes. We had to add a few units (i.e. variants) to the uses clause here and there and fiddle with conditional defines in a few places to get it to compile with both D5 and D2006. A third party component was not a backward compatible as you cold wish but in general the major work was done in less than a day.

But there where one big issue that we had to address first. The size of the project was about a few hundred forms and half a million lines of code. It took 90 minutes to compile in D5 and even longer in D2006. What is going on here? Ninety minutes for half a million lines of code is not the speed of the lightning fast Pascal compiler as I know it!

After analyzing the code I found that there was a general pattern of including a lot of units in the uses-clause in every unit. It appeared that this crisscross of references had a non-linear time complexity on the compiler. The only way to fix it immediately was to remove as many units as you can from the uses-clause in the interface section or move them to the implementation section. I imagined a nightmare of daunting manual work…

In the end the recipe to fix this was rather simple. It involves some free tools and open source tools but it does the job automatic. And the result was a rather successful optimization. We reduced compiled time from 90 minutes to 50 seconds – over 100 times! And the linker could remove 100.000 lines of unused code. I was pretty pleased with myself that evening. 🙂


  • ICARUS – a free tool from the maker of Pascal Analyzer. http://www.peganza.com/products.htm. Icarus parses Delphi or Borland Pascal source code and generates a Uses Report. This report will help you remove unneeded units from your uses lists. You will also know which units that can be moved from the interface uses list to the implementation uses list.
  • Uses Cleanup Tool – by Oleg Zhukov http://cc.borland.com/Item.aspx?id=23199.


  • Run ICARUS on your delphi project to get a report of which units depends on each other.
  • Input this report in the Uses Cleanup tool to automatically update all uses-clauses in your source code.
  • Delete all DCU-files and recompile.