Is 'uses' directive in Delphi's unit makes application bigger or slower?
I want to know from people who are smarter than me about Delphi, if there's a lot of unit imports in 'uses' directive, is it making my application slower or bigger?
Or if there's a lot of units that I 开发者_开发技巧import but not using, is it better to remove them?
Referencing units which you don't use slows down compilation but doesn't affect compiled application size much (as the unused code is not linked in) unless the unit has initialization or finalization parts. If it has, the unit is linked.
Also I should note, that the more units you have, the slower intellisense works.
In short, using units that you don't need to will result in larger executables. Usually it makes little difference to performance of the code.
Tools like Gexperts and CnPack have wizards to automatically remove unused units.
The main thing you can do to reduce executable size is to disable RTTI.
EDIT: In older versions of Delphi, the linker removes unused methods from the executable. Even then, code in the initialization/finalization sections of unused methods can result in extra code being linked into the executable and thus increasing its size.
Delphi 2010 introduced a new improved version of RTTI. One of the side effects of this is that unused functions are no longer removed by the linker. This behaviour can be customised to some degree.
Each unique uses in your app makes your app larger, because it means there's more code in the finished product.
Don't worry about unused classes, though. If the compiler can prove that it's not used anywhere in your code, it will remove it on its own. It can even remove entire units if no code in them is touched.
精彩评论