Slide 1

Slide 1 text

Java Module & Ahead Of Time Compilation Battle of Efficiency Luram Archanjo

Slide 2

Slide 2 text

Who am I? ● Software Engineer at Sensedia ● MBA in Java projects ● Java and Microservice enthusiastic

Slide 3

Slide 3 text

Agenda ● Microservices ● Java Module ● Ahead Of Time Compilation (AOT) ● Just In Time Compilation (JIT) ● Native Image ● Questions

Slide 4

Slide 4 text

Moving to Microservices Feature A Feature B Feature C Monolith Microservice Microservice Microservices Microservice

Slide 5

Slide 5 text

Scalability Feature A Monolith Scalability Microservice Microservice Microservices Scalability Microservice Microservice Microservice Microservice Microservice Microservice Microservice Microservice Feature B Feature C Feature A Feature B Feature C Feature A Feature B Feature C Waste Waste Waste Waste Waste

Slide 6

Slide 6 text

Our resources are finite!

Slide 7

Slide 7 text

How to use less resources using Java Language?

Slide 8

Slide 8 text

Java Module

Slide 9

Slide 9 text

Java Module Source: https://jcp.org/en/jsr/detail?id=376 & https://www.oracle.com/corporate/features/understanding-java-9-modules.html Modularity adds a higher level of aggregation above packages. The key new language element is the module - a uniquely named, reusable group of related packages, as well as resources and a module descriptor specifying. According to JSR 376, the key goals of modularizing the Java SE platform are: ● Reliable Configuration ● Strong Encapsulation ● Greater Platform Integrity ● Scalable Java Platform ● Improved Performance Module Package Class Field Method

Slide 10

Slide 10 text

Java Module java.se java.sql.rowset java.sql java.logging java.naming java.rmi java.scripting java.xml java.base java.datatransfer java.compiler java.desktop JDK Modules java.sql java.logging java.naming java.base java.compiler Application & Custom JRE module-info.java module myApp { exports com.tdc.poa; requires java.base; requires java.sql; requires java.logging; requires java.naming; requires java.compiler; }

Slide 11

Slide 11 text

What are the results of using Java Modules?

Slide 12

Slide 12 text

What are the results of using Java Modules? Java 8

Slide 13

Slide 13 text

What are the results of using Java Modules? Java 9 Module

Slide 14

Slide 14 text

Less classes, functions and dependencies are not enough!

Slide 15

Slide 15 text

The villain of Java’s resources is the Reflection

Slide 16

Slide 16 text

What are the results of using Reflection? 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 17

Slide 17 text

Is it possible to have the same productivity but without Reflection?

Slide 18

Slide 18 text

Yes, with Ahead Of Time (AOT) Compilation

Slide 19

Slide 19 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 20

Slide 20 text

What are the results of using Ahead Of Time (AOT) Compilation?

Slide 21

Slide 21 text

Data from Micronaut website: ● Startup time around a second. ● All Dependency Injection, AOP and Proxy generation happens at compile time. ● Can be run with as little as 180mb Max Heap. What are the results of using Ahead Of Time (AOT) Compilation?

Slide 22

Slide 22 text

Data from Quarkus website: ● Startup time around two seconds. ● All Dependency Injection, AOP and Proxy generation happens at compile time. ● Can be run with as little as 145mb Max Heap. What are the results of using Ahead Of Time (AOT) Compilation?

Slide 23

Slide 23 text

Is it possible to improve more?

Slide 24

Slide 24 text

Yes, with Just In Time (JIT) Compilation and

Slide 25

Slide 25 text

GraalVM is a universal virtual machine for running applications written in JavaScript, Python, Ruby, R, JVM-based languages like Java, Scala, Groovy, Kotlin, Clojure, and LLVM-based languages such as C and C++ ● Native Image ● Embeddable For Java Programs For existing Java applications, GraalVM can provide benefits by running them faster, providing a faster Just In Time (JIT) Compilation Source: https://www.graalvm.org/docs/why-graal/ what is?

Slide 26

Slide 26 text

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 Just In Time (JIT) Compilation System.out.println( "Hello World"); Source code 6a 61 76 61 20 c3 a9 20 66 6f 64 61 Byte code 01101010 01100001 01110110 01100001 00100000 11101001 00100000 01100110 01101111 01100100 01100001 Machine code JIT

Slide 27

Slide 27 text

What are the results of using Just In Time (JIT) Compilation?

Slide 28

Slide 28 text

What are the results of using Just In Time (JIT) Compilation?

Slide 29

Slide 29 text

What are the results of using Just In Time (JIT) Compilation?

Slide 30

Slide 30 text

Is it possible to improve more?

Slide 31

Slide 31 text

Yes, with Native Image and

Slide 32

Slide 32 text

GraalVM Native Image, currently available as an Early Adopter Technology Native image works well when: ● Little or no runtime reflection is used. ● Limited or no dynamic classloading. Source: https://www.graalvm.org/docs/why-graal/ Native Image

Slide 33

Slide 33 text

What are the results of using Native Image?

Slide 34

Slide 34 text

What are the results of using Native Image? Source: https://www.graalvm.org/docs/why-graal/

Slide 35

Slide 35 text

What are the results of using Native Image? Source: https://www.graalvm.org/docs/why-graal/

Slide 36

Slide 36 text

When to start using Java Module, AOT, JIT or Native Image?

Slide 37

Slide 37 text

When to start using Java Module, JIT or AOT? New Application Java Module ● Java 9 Just In Time Compilation ● GraalVM Ahead Of Time Compilation ● Quarkus ● Micronaut Native Image ● GraalVM ○ Early Adopter Technology Existent Application Java Module ● Java 9 Just In Time Compilation ● GraalVM

Slide 38

Slide 38 text

Java is dying?

Slide 39

Slide 39 text

Thanks a million! Questions? /larchanjo /luram-archanjo