On a modern computer with multiple cores the total compile time of an application is related to the longest path though the dependency graph of the application.
In a statically type checked language that supports separate compilation of application components (into, for example jars or assemblies), it is generally necessary to compile the dependencies of an application or library before compiling the application or library itself.
A typical layered application might look like this:
The compile order for such an application would be library4 then library3 then library2 then library1 then application. The longest path through the dependency graph is 5.
Assuming, for simplicity, that the compile time for each module is approximately the same (
m) the total compile time for the application (
t = 5m
Taking Advantage of Parallel Compilation
We can restructure our application using the dependency inversion principal. We split each layer into an abstract (interface) layer and a concrete implementation layer.
The application module becomes responsible for selecting the concrete implementation of each layer and configuring the layers of the application. This design pattern is known as Inversion of Control.
The compile order for such an application is much more flexible than that of the earlier design allowing some modules to be compiled in parallel.
The longest path through the dependency graph is 3.
Assuming again, that the compile time for each module is approximately the same (
m) the minimum compile time for the application (
t = 3m