Native Image, AOT, or JIT
When to use in your Java
Architecture
Luram Archanjo
Slide 2
Slide 2 text
Software Engineer at Zup Innovation
MBA in Java projects
Java and Microservice enthusiastic
Who am I?
Slide 3
Slide 3 text
Agenda
Goal
Types of Architectures
Ahead of time (AOT) compilation
Native Image
Just in time (JIT) compilation
Questions
Slide 4
Slide 4 text
Goal
Slide 5
Slide 5 text
Types of Architectures
Distributed
● Microservices
● Event Driven
● Serverless
Centralized
● Monolithic
● Data Centric
Slide 6
Slide 6 text
But Architecture
X is better than Y
Slide 7
Slide 7 text
Find the balance
of your
Architecture
Slide 8
Slide 8 text
All Architecture
has finite
resources!
Slide 9
Slide 9 text
How to use less
resources using
Java language?
Slide 10
Slide 10 text
Java Module?
Microframeworks?
Quarkus?
Micronaut?
Slide 11
Slide 11 text
None of them!
First, we need to
find the Root
Cause!
Slide 12
Slide 12 text
The villain of
Java’s resources
is the Reflection
Slide 13
Slide 13 text
How Spring and Jakarta EE work?
Spring is an amazing technical achievement and does
so many things, but does them at Runtime.
● Reads the byte code of every bean it finds.
● Synthesizes new annotations for each
annotation on each bean method, constructor,
field etc. to support Annotation metadata.
● Builds Reflective Metadata for each bean for
every method, constructor, field etc.
Slide 14
Slide 14 text
The use of Reflection!
Slide 15
Slide 15 text
Is it possible to have
the same productivity
but without
Reflection?
Slide 16
Slide 16 text
Yes, with Ahead
Of Time (AOT)
Compilation
Slide 17
Slide 17 text
Ahead of Time (AOT) Compilation
Ahead-of-time compilation (AOT compilation) is the
act of compiling a higher-level programming
language, or an intermediate representation such as
Java bytecode, into a native machine code so that
the resulting binary file can execute natively.
Web Android
Java
Google
Dagger 2
Slide 18
Slide 18 text
What are the results
of using Ahead Of
Time (AOT)
Compilation?
GraalVM
● Native Image
● Ahead-of-Time Compilation
● For existing Java applications, GraalVM can
provide benefits by running them faster,
providing a faster Just In Time (JIT) Compilation
Slide 23
Slide 23 text
GraalVM
GraalVM Native Image allows you to ahead-of-time
compile Java code to a standalone executable, called
a native image.
Source: https://www.graalvm.org/docs/reference-manual/native-image/
Slide 24
Slide 24 text
GraalVM - Limitations
Dynamic Class Loading: Deploying jars, wars, etc. at
runtime impossible.
Reflection: Requires registration via native-image
CLI/API.
Dynamic Proxy: No agents: JMX, JRebel, Byteman,
profilers, tracers, etc.
Slide 25
Slide 25 text
What are the results
of using Native
Image?
Slide 26
Slide 26 text
Source: https://www.graalvm.org/docs/why-graal/
Slide 27
Slide 27 text
Source: https://www.graalvm.org/docs/why-graal/
Slide 28
Slide 28 text
Early Adopter
Technology!
Slide 29
Slide 29 text
I don’t use Quarkus,
Micronaut and Helidon!
How can I improve my
current system?
Slide 30
Slide 30 text
What about the Just
In Time (JIT)
Compilation?
Slide 31
Slide 31 text
Just In Time (JIT) Compilation
Just In Time (JIT) compilation is a way of executing
computer code that involves compilation during
execution of a program. It runs complex
optimizations to generate high-quality machine code
System.out.prin
tln("Hello
World");
Source code
6a 61 76 61 20
c3 a9 20 66 6f
64 61
Byte code
01101010
01100001
0100000
Machine code
JIT
Slide 32
Slide 32 text
What are the results
of using Just In Time
(JIT) Compilation?
Slide 33
Slide 33 text
Twitter
Every company is constantly looking into ways to
increase availability of the platform while keeping an
eye on costs. Twitter saw Oracle GraalVM, a
language-independent compiler engine and virtual
machine, and decided to try it. Average CPU savings
for compiler innovation are in the 1–2 percent range,
but using Oracle GraalVM, Twitter realized between
8 and 11 percent CPU savings, depending on the
microservice ported.
Source: https://www.constellationr.com/research/how-oracle-graalvm-supercharged-twitter-s-microservices-platform
Slide 34
Slide 34 text
What are the results of using Just
In Time (JIT) Compilation?
Slide 35
Slide 35 text
A lot of cool
initiatives!
Let us recap?
Slide 36
Slide 36 text
2º Place
1º Place
3º Place
Ahead of Time (AOT)
Compilation
● Low memory
footprint
● Fast Startup
● IoC & SQL
Native Image
● Low memory
footprint 5x lower
● Fast Startup 50x
lower
● Early Adopter
Technology
Just in Time (JIT)
Compilation
● Latency
● Throughput
Summary
Slide 37
Slide 37 text
Native Image, AOT, or
JIT?
When to use in your
Java Architecture?
Slide 38
Slide 38 text
Native Image, AOT, or JIT? When to
use in your Java Architecture?
Existent
Application
New Application
Serverless & CLI
Ahead Of Time
Compilation
● Spring*
● Quarkus
● Micronaut
● Helidon
Just In Time
Compilation
● GraalVM
○ Java 8
○ Java 11
● Community
● Enterprise
Native Image
● GraalVM
Slide 39
Slide 39 text
Java is dying?
Slide 40
Slide 40 text
Thanks a million!
Questions?
/larchanjo
/luram-archanjo