The Economics of Just in Time (JIT) vs Ahead of Time (AOT) Compilation in Angular Development Environments

Rinkesh Patel
3 min readJan 7, 2023

--

In this article I am explaining about an often-overlooked benefit of Just in Time (JIT) compilation in Angular: improved economics on large codebases.

First let’s understand Just In Time compilation model and Ahead of Time Compilation model in simple terms.

Ahead of Time compilation: All compilation happens before the deployment. So, the application bundle doesn’t need Angular compiler in the browser.

Just In Time compilation: Some compilation happens during build, while other compilation happens in the browser during runtime as and when components are loaded.

Both these compilation models have their own pros and cons, but developers should use discretion while using them in development mode.

How did I notice this?

On a day-to-day basis, I work on a large code base in the latest stable angular development environment. For the last few months, what I have noticed is that the build and rebuilds becoming extremely slow as the code size grew. I remember that initially the builds were fast on a Dell machine with these specifications:

  • RAM: 16 GB
  • 11th Gen Intel Core i7–11390H @3.40GHz 2.92GHz
  • Windows 11 Pro

Depending on the load on the machine, it used to take somewhere in between 3–7 minutes for initial build and rebuilds. One day having gone through a stackoverflow, I experimented with setting ‘aot:false’ in the build configuration as suggested by answer 7, and it was like a miracle. The builds used to complete within 1 minute most of the time. So, keeping all other properties of the configuration same and only turning off AOT, it can result into the savings of 2–6 minutes per build and a few milliseconds in rebuilds.

This experience led me to delve deeper into AOT and JIT compilation models. I realised that AOT is made for production environments or for end-users but not for developers.

The key drawbacks of using AOT in developer mode (especially with ng serve)

Figure 1. Average daily loss of a developer in slower builds and rebuilds
Figure 2. Average daily loss per team based on average 10 mins of lost time waiting for build and rebuilds
  • 5 developers work on a code base. Each developer is responsible for managing parts of the code base. Why should a developer wait for compiling the entire code base upfront when they are going to develop and test only parts of it?
  • On an average 10 minutes of loss per developer per day can cost somewhere in between $5000–$6000 per year per team as shown in figure 1 and 2 above.
  • Machines are more patient than humans, so AOT should be used for automated builds which are triggered when someone merges code with the master branches. That way we can still get the benefits of AOT without compromising the team productivity.

Key Solution

  • turn off AOT by setting ‘aot:false’ in the build configuration in developer environments (local builds, while using ng serve)

Potential alternative solutions to ‘aot:false’

  1. get more powerful machine ($$$$)
  2. modularize code (more modules)

To Summarize

Anything which makes developers wait more than 2 minutes can rake up thousands of dollars in the form of lost time and productivity. And ever more powerful machines are not always the answer to those problems. The effective answer to those problems lies in questioning the default behaviours.

Please feel free to leave your thoughts and comments.

--

--

Rinkesh Patel

A persistent problem solver trying to dig deeper into day-to-day challenges in Software Engineering and share insights. Love simple and effective solutions.