In today’s blog, I am going to explain Micronaut AOT. Micronaut AOT is a framework that implements ahead-of-time (AOT) optimizations for Micronaut applications. but before going deep let us see what Micronaut is and what is AOT.
It is a modern, JVM-based, full-stack microservices framework. Which is designed to avoid reflection, so it reduces memory consumption and improves start time. Features that are typically implemented at run-time are instead pre-computed at compile time. It is designed for building modular, easily testable microservices applications. Micronaut integrates cloud technology into the framework, and microservices patterns such as service discovery, and distributed tracing allow us to develop a full-featured microservices application using the Micronaut framework, similar to Spring. Micronaut uses Netty and has first-class support for reactive programming.
What is AOT :
As we are familiar with JIT (Just-In-Time) it compiles your app in the browser at runtime. Which makes it more suitable for development. Unlike JIT, AOT (Ahead-of-Time) compiles your app at build time on the server. Which makes it more suitable for production. It loads the page faster In comparison to JIT.
Micronaut AOT is a framework that reduces the start time of the application. It creates full compile and optimized code so Its bundle size will be half If you will compare it with other frameworks of java Like Spring Boot. Micronaut AOT also reduces deployment size by executing a number of operations during the build. It can precompute bean requirements and perform substitutions at build time so that only classes that are going to be used in production are included. It can generate specific optimizations for different environments, in particular, it can make a difference between optimizations needed in JIT mode
The goal of Micronaut AOT is to create an optimized “binary” for a particular deployment environment. It is not to make the development experience faster: because build time optimizations require deep analysis of the application, it will actually make the local development slower if you use optimized binaries.
Working Of MicroNaut AOT :
It reduces application startup time and deployment size by executing a number of operations during the build. It computes bean requirements before the build and performs substitutions at build time. So that only classes that are going to be used in production are included. We designed Micronaut AOT with an extension in mind, so other Micronaut libraries can deliver their own optimizations.
Here are some ways which are used by Micronaut AOT to optimize Micronaut code.
- It optimizes the service loading by pre-scanning the list of all the available services and implements parallel loading in JVM.
- It changes the YAML configuration to Java configuration to make apps start faster.
- When we use transitive dependencies it precomputes bean requirements to eliminate beans whose requirements won’t be met at runtime.
- It precomputes some complex and most used operations, like converting environment variable names to Micronaut configuration properties and many more.
To explore more about Micronaut AOT visit the link – Micronaut AOT