How can I reduce the size of my Delphi dll's?
Asked Answered
U

1

8

I recently moved from Delphi 7 to Delphi XE3.

A dll file that was 107kb in Delphi 7 is now compiling to 2.7 MB. Another that was 114kb is now 4.7 MB!

Is this normal? What might I do to reduce the file sizes? If you need more info please ask.

UPDATE:

Both dll files were already being compiled in release mode.

After following Mason's advice:

The 4.7MB file was reduced to 834kb and the 2.7MB file was reduced to 2.1MB. The 2.1MB file makes use of Generics and an external library called nExcel used for generating Excel files. Whilst nExcel was also used when the file size was smaller the use of Generics is a new addition to the code and I guess may be the reason for the file size remaining fairly large.

Urgent answered 8/10, 2012 at 1:25 Comment(2)
Be sure to compile your dll in release mode and remove the extended RTTI info from your dll using {$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])} {$WEAKLINKRTTI ON} Maurice
andy.jgknet.de/blog/2011/11/…Overflight
J
16

Some of it is unavoidable; the RTL has gotten bigger as more functionality was added. However, a lot of that size increase is going to be due to the addition of extended RTTI in Delphi 2010.

You can fix this by putting the following two lines in the main project file, before any uses clause:

{$RTTI EXPLICIT METHODS([]) PROPERTIES([]) FIELDS([])}
{$WEAKLINKRTTI ON}

These will cause the compiler to minimize extended RTTI throughout the project. (Be aware that this means that you won't have the RTTI functionality available. But since this is a Delphi 7 project, you probably aren't using it yet anyway. You'll want to read up on extended RTTI and see if you can find useful things to do with it.)

Jackdaw answered 8/10, 2012 at 1:37 Comment(7)
Thank you. RTTI, is this run time type info? Similar to reflection in C# perhaps?Urgent
AND do not forget to compile the dll in release mode, not in debug mode which increases the size a lot by adding debugging information to the executable.Haematoblast
@MasonWheeler Are you sure putting this in the main project file is enough? Official documentation states that it is a local directive, and I always used it as such, by inserting it in a .inc file called in all my units.Haematoblast
"@Steve: If that works, could you please add reduced DLLs size as comment here? So that other at least roughly knew what figures to expect from this tweak. Thanks.Henriquez
@arnaud top of the .dpr file is enoughFurred
@Urgent You've accepted this answer, but RTTI is not the main reason for the massive increase in size. That's down to the debug settings I believe.Furred
@KromStern The 4.7MB file was reduced to 834kb and the 2.7MB file was reduced to 2.1MB after adding the lines suggested by Mason. The 2.1MB file makes use of Generics and an external library called nExcel used for generating Excel files. The nExcel library has always been a part of the code, the use of generics was added with the latest updates. I followed the link from Arioch above regarding the debug settings but they all appear to be off. A few settings are checked such as Extended syntax and Optimise but I fear unchecking these may cause problems as I don't know what they're really for.Urgent

© 2022 - 2024 — McMap. All rights reserved.