Jump to content
Erik@Grijjy

Decrease Your Build Time

Recommended Posts

While LLVM certainly is part of the situation it suffers from the same sickness that makes most C++ code compile terribly slow: templates - err, I should say generics. (precompiled headers anyone?)

Especially FMX uses them like everywhere if it makes sense or not. Everything is a TList<something> and there are many generic types within FMX itself.

So the compiler has to build all these generics for each and every unit. Yes, if you have 1000 units using TList<TComponent> then that code is being emitted into 1000 dcu files and in case of LLVM also .o files including all that RTTI and possibly gigantic debug information for that TList<T>.

The linker later eliminates any duplicates so the final binary does contains the code and RTTI only once.

 

I know this from refactoring spring4d where I redesigned the generic collections to produce as little code as possible and turned off RTTI for all the implementing classes which improvided compile time on some projects by a factor of 4.

Unfortunately even with the new intrinsics introduced in XE7 that were for reducing binary size because it enables compiletime optimizations for the code (GetTypeKind and alike) there is some significant bloat happening as I reported some time ago.

When you fancy and look into a map file for a typical FMX application you can see that a huge chunk alone is from system.generics.collections and most of that code is dead code because it's only in the binary because RTTI is turned on for those classes.

Even if they are used as private fields in some classes and all that is ever called on them is Add and Delete the entire code is emitted by the compiler.

 

So a significant part of the compiletime is being used producing garbage (emitting code into dcu/o files) that the linker later has to find and eliminate.

 

Edit: To emphasize: generics alone are not bad - its the overuse of them and making them fatter than they need to be and having RTTI being turned on for them. Often in places where a class reference would have been enough instead of some fancy<T: TSomethingclass>

Edited by Stefan Glienke
  • Like 6

Share this post


Link to post

Using precompiled dcu's is common sense really.. imagine if you had to build the rtl/vcl/fmx every time you build your application⏲️ 

 

In the dpm package manager I'm, working on, it compiles the packages/library when the library is installed (assuming its designed to do that) - so the first time you install the package it takes a bit longer, but then builds are a lot faster.  

 

Share this post


Link to post
17 hours ago, Stefan Glienke said:

I know this from refactoring spring4d where I redesigned the generic collections to produce as little code as possible and turned off RTTI for all the implementing classes which improvided compile time on some projects by a factor of 4.

Are you aware of any compilation of best practices to reduce code bloat and compilation size you are mentioning here ref your refactoring?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×